Class: Threatinator::CLI::Parser
- Inherits:
-
Object
- Object
- Threatinator::CLI::Parser
- Includes:
- Helpers
- Defined in:
- lib/threatinator/cli/parser.rb
Instance Attribute Summary collapse
-
#builder ⇒ Object
Returns the value of attribute builder.
-
#config_hash ⇒ Object
readonly
Returns the value of attribute config_hash.
-
#extra_args ⇒ Object
readonly
Returns the value of attribute extra_args.
-
#run_action_config_class ⇒ Object
readonly
Returns the value of attribute run_action_config_class.
Instance Method Summary collapse
- #_init_mod ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse(args) ⇒ Object
- #set_opts(global_options, options, args) ⇒ Object
Methods included from Helpers
#add_cli_args, #clean_opts, #fix_opts, #nest_opts
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
59 60 61 62 63 64 65 |
# File 'lib/threatinator/cli/parser.rb', line 59 def initialize @builder = nil @plugin_loader = Threatinator::PluginLoader.new @plugin_loader.load_all_plugins @run_action_config_class = Threatinator::Actions::Run::Config.generate(@plugin_loader) @mod = _init_mod end |
Instance Attribute Details
#builder ⇒ Object
Returns the value of attribute builder.
55 56 57 |
# File 'lib/threatinator/cli/parser.rb', line 55 def builder @builder end |
#config_hash ⇒ Object (readonly)
Returns the value of attribute config_hash.
56 57 58 |
# File 'lib/threatinator/cli/parser.rb', line 56 def config_hash @config_hash end |
#extra_args ⇒ Object (readonly)
Returns the value of attribute extra_args.
56 57 58 |
# File 'lib/threatinator/cli/parser.rb', line 56 def extra_args @extra_args end |
#run_action_config_class ⇒ Object (readonly)
Returns the value of attribute run_action_config_class.
57 58 59 |
# File 'lib/threatinator/cli/parser.rb', line 57 def run_action_config_class @run_action_config_class end |
Instance Method Details
#_init_mod ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/threatinator/cli/parser.rb', line 76 def _init_mod parser = self Module.new do extend Helpers extend GLI::App program_desc 'Threatinator!' add_cli_args(self, Threatinator::Config::Logger.properties('logger')) add_cli_args(self, Threatinator::Config::FeedSearch.properties('feed_search')) desc "fetch and parse a feed" command :run do |c| c.flag 'run.coverage_output', type: String, desc: "Write coverage analysis to the specified file (CSV format)" add_cli_args(c, parser.run_action_config_class.properties('run')) c.action do |, , args| if ["run.feed_provider"].nil? ["run.feed_provider"] = args.shift end if ["run.feed_name"].nil? ["run.feed_name"] = args.shift end parser.set_opts(, , args) builder = Threatinator::CLI::RunActionBuilder.new(parser.config_hash, parser.extra_args, parser.run_action_config_class) parser.builder = builder end end desc 'list out all the feeds' command :list do |c| add_cli_args(c, Threatinator::Actions::List::Config.properties('list')) c.action do |, , args| parser.set_opts(, , args) parser.builder = Threatinator::CLI::ListActionBuilder.new(parser.config_hash, parser.extra_args) end end end end |
#parse(args) ⇒ Object
67 68 69 |
# File 'lib/threatinator/cli/parser.rb', line 67 def parse(args) @mod.run(args) end |
#set_opts(global_options, options, args) ⇒ Object
71 72 73 74 |
# File 'lib/threatinator/cli/parser.rb', line 71 def set_opts(, , args) @config_hash = fix_opts(.merge()) @extra_args = args end |