Class: Usps::Imis::CommandLine::OptionsParser
- Inherits:
-
Object
- Object
- Usps::Imis::CommandLine::OptionsParser
- 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 or Business Object name to query', { type: :string, short: :Q }], mapper: ['Interact with mapped fields', { short: :M }], map: ["Shorthand for accessing a single mapped field\n Equivalent to #{'-Mf'.green}", { type: :string }], 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 }], data: ["JSON string input\n When present, sets the default HTTP verb to #{'PUT'.cyan}", { 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 #{'iMIS ID'.yellow} and #{'Ordinal'.yellow} properties in returned data, if present"], quiet: ["Suppress logging to #{'STDERR'.red}"], log: ["Redirect logging to #{'STDOUT'.red}"], 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], %i[raw include_ids], %i[quiet log_level], %i[quiet log], %i[post delete], %i[post mapper], %i[post query], %i[post map], %i[delete mapper], %i[delete query], %i[delete map] ].freeze
- DEPENDENT_OPTION_PAIRS =
[ %i[ordinal panel] ].freeze
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ OptionsParser
constructor
A new instance of OptionsParser.
Constructor Details
#initialize ⇒ OptionsParser
Returns a new instance of OptionsParser.
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/usps/imis/command_line/options_parser.rb', line 101 def initialize @options = .compact @arguments = ARGV # Not currently used # :nocov: @options[:data] = read_stdin if stdin? # :nocov: @options[:data] = JSON.parse(@options[:data]) if @options[:data] end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
54 55 56 |
# File 'lib/usps/imis/command_line/options_parser.rb', line 54 def arguments @arguments end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
54 55 56 |
# File 'lib/usps/imis/command_line/options_parser.rb', line 54 def @options end |
Class Method Details
.banner_contents ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/usps/imis/command_line/options_parser.rb', line 56 def self. <<~BANNER #{'Usage'.underline} #{'imis.rb'.bold} #{'[options]'.gray} #{'HTTP Verbs'.underline} 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'.underline} API configuration can be specified in two ways: With #{'--config'.green}/#{'-C'.green} given the path to a JSON file, e.g.: { "imis_id_query_name": "#{'$/IQA_QUERY_NAME'.yellow}", "environment": "#{'development'.yellow}", "username": "#{'USERNAME'.yellow}", "password": "#{'PASSWORD'.yellow}" } By setting the following environment variables: #{'IMIS_ID_QUERY_NAME'.yellow} #{'IMIS_ENVIRONMENT'.yellow} #{'IMIS_USERNAME'.yellow} #{'IMIS_PASSWORD'.yellow} #{'Options'.underline} BANNER end |