class Threatinator::CLI::Parser

Attributes

builder[RW]
config_hash[R]
extra_args[R]
run_action_config_class[R]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

_init_mod() click to toggle source
# 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 |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

        parser.set_opts(global_options, options, 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 |global_options, options, args|
        parser.set_opts(global_options, options, args)
        parser.builder = Threatinator::CLI::ListActionBuilder.new(parser.config_hash, parser.extra_args)
      end
    end
  end
end
parse(args) click to toggle source
# File lib/threatinator/cli/parser.rb, line 67
def parse(args)
  @mod.run(args)
end
set_opts(global_options, options, args) click to toggle source
# File lib/threatinator/cli/parser.rb, line 71
def set_opts(global_options, options, args)
  @config_hash = fix_opts(global_options.merge(options))
  @extra_args = args
end