Class: Usps::Imis::CommandLine::OptionsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/usps/imis/command_line/options_parser.rb

Overview

Command line options parser

Constant Summary collapse

OPTIONS =
{
  certificate: ['Member certificate number', { type: :string }],
  id: ['Member iMIS ID', { type: :integer }],
  on: ['Business Object name', { type: :string }],
  panel: ['Panel name', { type: :string }],
  ordinal: ['Ordinal ID within a Panel', { type: :integer }],
  query: ['IQA Query name', { type: :string, short: :Q }],
  post: ["Send a #{'POST'.cyan} request", { short: :P }],
  delete: ["Send a #{'DELETE'.cyan} request", { short: :D }],
  field: ['Specific field to return or update', { type: :string }],
  fields: ['Specific field(s) to return', { type: :strings, short: :F }],
  map: ['Mapped field name to return or update', { type: :string }],
  data: ['JSON string input', { type: :string }],
  config: ['Path to the JSON config file to use', { type: :string, short: :C }],
  raw: ['Return raw JSON output, rather than simplified data', { short: :R }],
  include_ids: ['Include ID properties in returned data'],
  quiet: ['Suppress logging to STDERR'],
  log: ['Redirect logging to STDOUT'],
  log_level: ['Set the logging level', { type: :string, default: 'info', short: :L }]
}.freeze
CONFLICTING_OPTION_GROUPS =
[
  %i[certificate id],
  %i[on panel query map],
  %i[field fields map query]
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptionsParser

Returns a new instance of OptionsParser.



61
62
63
64
65
66
67
68
69
70
# File 'lib/usps/imis/command_line/options_parser.rb', line 61

def initialize
  @options = parse_options.compact
  @arguments = ARGV # Not currently used

  # :nocov:
  @options[:data] = read_stdin if stdin?
  # :nocov:

  @options[:data] = JSON.parse(@options[:data])
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



36
37
38
# File 'lib/usps/imis/command_line/options_parser.rb', line 36

def arguments
  @arguments
end

#optionsObject (readonly)

Returns the value of attribute options.



36
37
38
# File 'lib/usps/imis/command_line/options_parser.rb', line 36

def options
  @options
end

Class Method Details



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/usps/imis/command_line/options_parser.rb', line 38

def self.banner_contents
  <<~BANNER
    Usage:
      imis.rb #{'[options]'.gray}

      The default HTTP verb is #{'GET'.cyan}.
      If #{'--data'.green}/#{'-d'.green} is provided, the default HTTP verb is #{'PUT'.cyan}.

      #{'--data'.green}/#{'-d'.green} is used to provide field(s) data for #{'PUT'.cyan}
      requests and mapper updates, object data for #{'POST'.cyan},
      and to provide any query params.

      Configuration can be specified with #{'--config'.green}/#{'-C'.green}, or by setting
      the following environment variables:
        #{'IMIS_ENVIRONMENT'.yellow}
        #{'IMIS_USERNAME'.yellow}
        #{'IMIS_PASSWORD'.yellow}
        #{'IMIS_ID_QUERY_NAME'.yellow}

    Options:
  BANNER
end