- 
                Notifications
    You must be signed in to change notification settings 
- Fork 114
add: fpm search #1054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
add: fpm search #1054
Changes from all commits
7d5a99d
              06d353c
              94fdf25
              0a4f910
              7a4bdb5
              cc9bd57
              0a99d4a
              b048451
              0b66b85
              d2b173a
              6d5c44b
              354fda1
              baed1f5
              3456c39
              384ef93
              ea021d3
              7dbd3f7
              11c05cb
              762b78e
              08f0171
              511a107
              a87b472
              5f3a18d
              334eeb5
              a0dbf40
              494194f
              5eb04a5
              034051d
              373155c
              18c3975
              606c20a
              e9822d9
              c1216f0
              fc62c32
              ced681e
              52b0d79
              0ca0eae
              4a4c6ce
              8800925
              b02bd72
              e05e51d
              469051f
              c1b0c18
              aa1112b
              8496b5c
              4beb573
              5c259a4
              1c86fdf
              4a1975f
              0f668a5
              dad1f49
              c3f27ba
              81ea75b
              805f1e5
              a62162a
              ad779ec
              2d088aa
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,178 @@ | ||||||
| !> Search a package from both local and remote registry using the `search` subcommand. | ||||||
| !> The package can be searched by packagename, namespace, query (description and README.md), and license from the registries (local and remote). | ||||||
| !> the remote registry URL can also be specified by the paramter --registry. | ||||||
| !> It can be used as `fpm search --query q* --page 1 --registry URL --namespace n* --package p* --package_version v* --license l* --limit 10 --sort-by [name] --sort [asc/desc]` | ||||||
| module fpm_cmd_search | ||||||
| use fpm_command_line, only: fpm_search_settings | ||||||
| use fpm_manifest, only: package_config_t, get_package_data | ||||||
| use fpm_model, only: fpm_model_t | ||||||
| use fpm_error, only: error_t, fpm_stop | ||||||
| use fpm_versioning, only: version_t | ||||||
| use fpm_filesystem, only: exists, join_path, get_temp_filename, delete_file, basename, & | ||||||
| canon_path, dirname, list_files, is_hidden_file | ||||||
| use fpm_git, only: git_archive | ||||||
| use fpm_downloader, only: downloader_t | ||||||
| use fpm_strings, only: string_t, string_array_contains, split, str,glob | ||||||
| use fpm, only: build_model | ||||||
| use fpm_error, only : error_t, fatal_error, fpm_stop | ||||||
| 
     | ||||||
| use jonquil, only : json_object | ||||||
| use tomlf, only : toml_array, get_value, len, toml_key, toml_loads, toml_table, & | ||||||
| toml_serializer,toml_value | ||||||
| use tomlf_utils_io, only : read_whole_file | ||||||
| use fpm_settings, only: fpm_global_settings, get_global_settings, official_registry_base_url | ||||||
|  | ||||||
| implicit none | ||||||
| private | ||||||
| public :: cmd_search | ||||||
|  | ||||||
| contains | ||||||
|  | ||||||
| !> Search the fpm registry for a package | ||||||
| subroutine cmd_search(settings) | ||||||
| !> Settings for the search command. | ||||||
| class(fpm_search_settings), intent(in) :: settings | ||||||
| type(fpm_global_settings) :: global_settings | ||||||
| character(:), allocatable :: tmp_file, name, namespace, description, query_url, package_version | ||||||
| integer :: stat, unit, ii | ||||||
| type(json_object) :: json | ||||||
| type(json_object), pointer :: p | ||||||
| !> Error handling. | ||||||
| type(error_t), allocatable :: error | ||||||
| type(toml_array), pointer :: array | ||||||
| type(version_t), allocatable :: version | ||||||
|  | ||||||
| !> Downloader instance. | ||||||
| class(downloader_t), allocatable :: downloader | ||||||
| allocate (downloader) | ||||||
|  | ||||||
| call get_global_settings(global_settings, error) | ||||||
| if (allocated(error)) then | ||||||
| call fpm_stop(1, "Error retrieving global settings"); return | ||||||
| end if | ||||||
|  | ||||||
| !> Generate a temporary file to store the downloaded package search data | ||||||
| tmp_file = get_temp_filename() | ||||||
| open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat) | ||||||
| if (stat /= 0) then | ||||||
| call fatal_error(error, "Error creating temporary file for downloading package."); return | ||||||
| end if | ||||||
| query_url = settings%registry//'/packages_cli' & | ||||||
| & // '?query='//settings%query & | ||||||
| & // '&page='//settings%page & | ||||||
| & // '&package='//settings%package & | ||||||
| & // '&namespace='//settings%namespace & | ||||||
| & // '&version='//settings%version & | ||||||
| & // '&license='//settings%license & | ||||||
| & // '&limit='//settings%limit & | ||||||
| & // '&sort_by='//settings%sort_by & | ||||||
| & // '&sort='//settings%sort | ||||||
|  | ||||||
| !> Get the package data from the registry | ||||||
| call downloader%get_pkg_data(query_url, version, tmp_file, json, error) | ||||||
| close (unit) | ||||||
| if (allocated(error)) then | ||||||
| call fpm_stop(1, "Error retrieving package data from registry: "//settings%registry); return | ||||||
| end if | ||||||
| print * | ||||||
| print *, "Searching packages in Local Registry:" | ||||||
| print * | ||||||
| call search_package(settings%query, settings%namespace, settings%package, settings%version) | ||||||
| if (json%has_key("packages")) then | ||||||
| call get_value(json, 'packages', array) | ||||||
| print * | ||||||
| print '(A,I0,A)', ' Found ', len(array), ' packages in fpm - registry:' | ||||||
| 
     | ||||||
| print '(A,I0,A)', ' Found ', len(array), ' packages in fpm - registry:' | |
| print '(A,I0,A)', ' Found ', len(array), ' packages in fpm-registry:' | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple issues: 'packagename' should be 'package name', 'paramter' should be 'parameter', and the second line should start with a capital letter.