Class: Threatinator::CLI::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/threatinator/cli/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



55
56
57
58
59
60
61
# File 'lib/threatinator/cli/parser.rb', line 55

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

#builderObject

Returns the value of attribute builder.



52
53
54
# File 'lib/threatinator/cli/parser.rb', line 52

def builder
  @builder
end

#run_action_config_classObject (readonly)

Returns the value of attribute run_action_config_class.



53
54
55
# File 'lib/threatinator/cli/parser.rb', line 53

def run_action_config_class
  @run_action_config_class
end

Instance Method Details

#_init_modObject



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
100
101
102
103
104
105
106
107
# File 'lib/threatinator/cli/parser.rb', line 67

def _init_mod
  parser = self
  Module.new do
    extend Helpers
    extend GLI::App

    program_desc 'Threatinator!'

    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 |global_options, options, args|
        if options["run.feed_provider"].nil?
          options["run.feed_provider"] = args.shift
        end

        if options["run.feed_name"].nil?
          options["run.feed_name"] = args.shift
        end

        opts = fix_opts(global_options.merge(options))

        builder = Threatinator::CLI::RunActionBuilder.new(opts, 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 |global_options, options, args|
        opts = fix_opts(global_options.merge(options))
        parser.builder = Threatinator::CLI::ListActionBuilder.new(opts, args)
      end
    end
  end
end

#parse(args) ⇒ Object



63
64
65
# File 'lib/threatinator/cli/parser.rb', line 63

def parse(args)
  @mod.run(args)
end