Class: Usps::Imis::CommandLine::Interface

Inherits:
Object
  • Object
show all
Includes:
Performers
Defined in:
lib/usps/imis/command_line/interface.rb

Overview

Command line interface for the Api

Constant Summary collapse

CONFIG_PATHS =

Prioritized list of config file paths to automatically check if not provided

{
  local_dot: File.join(Dir.pwd, '.imis.yml'),
  local: File.join(Dir.pwd, 'imis.yml'),
  local_dot_config: File.join(Dir.pwd, '.config', 'imis.yml'),
  local_config: File.join(Dir.pwd, 'config', 'imis.yml'),
  user: "#{Dir.home}/.config/imis.yml",
  system: '/usr/local/imis/config.yml'
}.freeze
RAW_HASH_RESPONSE_OPTIONS =

CLI options that indicate the response is a raw Hash rather than a Data object, and should not be simplified

%i[business_objects auth_token].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInterface

A new instance of Interface

Parameters:

  • Options (**Hash)

    from the CLI options parser



47
48
49
50
51
52
53
54
# File 'lib/usps/imis/command_line/interface.rb', line 47

def initialize(**)
  @options = input_options.merge(**)
  options[:version] = true if default_options?

  configure!
  logging!
  @logger ||= Imis.logger('CommandLine')
end

Instance Attribute Details

#loggerObject (readonly)

Tagged logger



35
36
37
# File 'lib/usps/imis/command_line/interface.rb', line 35

def logger
  @logger
end

#optionsObject (readonly)

Options passed in from the command line



31
32
33
# File 'lib/usps/imis/command_line/interface.rb', line 31

def options
  @options
end

Class Method Details

.runObject

Initialize an Interface and run it with the provided options

Parameters:

  • Options (**Hash)

    from the CLI options parser



41
# File 'lib/usps/imis/command_line/interface.rb', line 41

def self.run(...) = new(...).run

Instance Method Details

#runObject

Run the configured action on the API



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

def run
  logger.info 'Running'
  logger.debug 'CLI Options:'
  logger.json(options.dup.tap { it[:token] = '[FILTERED]' if it[:token] })

  set_member

  result = simplify(perform!)

  output { result }

  result
end