Class: FhirPackagesManager::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/fhir_packages_manager/cli.rb

Overview

Command-line entry point backing the fhir_packages_manager executable. See the "CLI" section of the README for usage examples.

Constant Summary collapse

COMMANDS =

Returns the supported subcommands.

Returns:

  • (Array<String>)

    the supported subcommands

%w[fetch check list sync].freeze
<<~USAGE
  Usage: fhir_packages_manager COMMAND package[@version] [package[@version] ...] [options]

  Commands:
    fetch   Download packages into the destination folder
    check   Report which registry (if any) has each package/version
    list    List every version of a package available across registries
    sync    Download every non-ignored version not already in the destination folder

USAGE

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • argv (Array<String>)

    see run



33
34
35
36
# File 'lib/fhir_packages_manager/cli.rb', line 33

def initialize(argv)
  @argv = argv.dup
  @options = { destination: './fhir_packages', registries: [] } # : Hash[Symbol, untyped]
end

Class Method Details

.run(argv) ⇒ void

This method returns an undefined value.

Parses argv and runs the requested command (fetch or check).

Parameters:

  • argv (Array<String>)

    arguments as passed to the executable, e.g. ARGV



28
29
30
# File 'lib/fhir_packages_manager/cli.rb', line 28

def self.run(argv)
  new(argv).run
end

Instance Method Details

#runvoid

This method returns an undefined value.



39
40
41
42
43
44
45
46
47
48
# File 'lib/fhir_packages_manager/cli.rb', line 39

def run
  parser.parse!(@argv)
  command = @argv.shift
  package_specs = @argv

  return usage_error(1) if !COMMANDS.include?(command) || package_specs.empty?
  return usage_error('Error: at least one --registry URL is required') if @options[:registries].empty?

  dispatch(command, package_specs)
end