Class: Snmp2mkr::Cli
- Inherits:
-
Object
- Object
- Snmp2mkr::Cli
- Defined in:
- lib/snmp2mkr/cli.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
Instance Method Summary collapse
- #config ⇒ Object
- #do_start ⇒ Object
-
#initialize(argv) ⇒ Cli
constructor
A new instance of Cli.
- #options ⇒ Object
- #optparse ⇒ Object
- #parse_argv ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ Cli
Returns a new instance of Cli.
7 8 9 |
# File 'lib/snmp2mkr/cli.rb', line 7 def initialize(argv) @argv = argv.dup end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
11 12 13 |
# File 'lib/snmp2mkr/cli.rb', line 11 def argv @argv end |
Instance Method Details
#config ⇒ Object
66 67 68 |
# File 'lib/snmp2mkr/cli.rb', line 66 def config @config ||= Snmp2mkr::Config.from_yaml(File.read([:config])) end |
#do_start ⇒ Object
26 27 28 29 30 |
# File 'lib/snmp2mkr/cli.rb', line 26 def do_start parse_argv engine = Engine.new(config, log_level: [:log_level]) engine.run! end |
#options ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/snmp2mkr/cli.rb', line 58 def ||= { log_level: 'info', config: './config.yml', config_chdir: false, } end |
#optparse ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/snmp2mkr/cli.rb', line 38 def optparse @optparse ||= OptionParser.new do |opt| opt.on('-c YAML', '--config YAML', 'specify configuration file (default ./config.yml)') do |path| [:config] = path end opt.on('-C', '--chdir-config-dir', 'chdir working directory to same as configuration file (default false)') do |path| [:config_chdir] = true end opt.on('-c YAML', '--config YAML', 'specify configuration file (default ./config.yml)') do |path| [:config] = path end opt.on('-l LOGLEVEL', '--log-level LOGLEVEL', 'log level (default "info")') do |l| [:log_level] = l end end end |
#parse_argv ⇒ Object
32 33 34 35 36 |
# File 'lib/snmp2mkr/cli.rb', line 32 def parse_argv optparse.parse(argv).tap do Dir.chdir(File.dirname([:config])) if [:config_chdir] end end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/snmp2mkr/cli.rb', line 13 def run case @argv.shift when 'start' do_start return 0 when 'test' raise NotImplementedError when 'import' raise NotImplementedError else end end |