diff options
| author | mokha <mokha@cisco.com> | 2018-03-19 14:59:13 -0600 |
|---|---|---|
| committer | mokha <mokha@cisco.com> | 2018-03-19 14:59:13 -0600 |
| commit | e044a9e9edf36c80fbd8756634058f009026a3f9 (patch) | |
| tree | f18c79257cf87f83523c757c1fbe3f067c67dcc7 | |
| parent | ab088fa5fffb62bcab37552fbe06e5f552813822 (diff) | |
merge the two command classes.
| -rw-r--r-- | lib/ats/cli.rb | 10 | ||||
| -rw-r--r-- | lib/ats/cli/amp4e/command.rb | 26 | ||||
| -rw-r--r-- | lib/ats/cli/command.rb | 32 | ||||
| -rw-r--r-- | lib/ats/cli/threat_grid.rb | 15 | ||||
| -rw-r--r-- | lib/ats/cli/threat_grid/command.rb | 26 |
5 files changed, 39 insertions, 70 deletions
diff --git a/lib/ats/cli.rb b/lib/ats/cli.rb index 60c3709..08d978a 100644 --- a/lib/ats/cli.rb +++ b/lib/ats/cli.rb @@ -1,8 +1,12 @@ require 'ats' - require 'thor' -require 'ats/cli/threat_grid' -require 'ats/cli/amp4e/command' +require 'ats/cli/command' +require 'ats/cli/threat_grid/organizations' +require 'ats/cli/threat_grid/samples' +require 'ats/cli/threat_grid/search' +require 'ats/cli/threat_grid/users' +require 'ats/cli/threat_grid/whoami' +require 'ats/cli/threat_grid/application' require 'ats/cli/amp4e/computers' require 'ats/cli/amp4e/events' require 'ats/cli/amp4e/groups' diff --git a/lib/ats/cli/amp4e/command.rb b/lib/ats/cli/amp4e/command.rb deleted file mode 100644 index 9e6a93a..0000000 --- a/lib/ats/cli/amp4e/command.rb +++ /dev/null @@ -1,26 +0,0 @@ -module ATS - module CLI - module AMP4E - class Command < Thor - class_option :profile, default: :default, required: false - - def self.printable_commands(*args) - super.map do |x| - x[0] = x[0].gsub(/^ats/, 'ats amp4e') - x - end - end - - protected - - def api - ATS::AMP4E::API.new(profile: options['profile']) - end - - def print_json(json) - say JSON.pretty_generate(json), :green - end - end - end - end -end diff --git a/lib/ats/cli/command.rb b/lib/ats/cli/command.rb new file mode 100644 index 0000000..77531eb --- /dev/null +++ b/lib/ats/cli/command.rb @@ -0,0 +1,32 @@ +module ATS + module CLI + class Command < Thor + class_option :profile, default: :default, required: false + + def self.printable_commands(*args) + super.map do |x| + x[0] = x[0].gsub(/^ats/, "ats #{service_name.downcase}") + x + end + end + + protected + + def api + self.class.constant_name.new(profile: options['profile']) + end + + def print_json(json) + say JSON.pretty_generate(json), :green + end + + def self.constant_name + Kernel.const_get("ATS::#{service_name}::API") + end + + def self.service_name + name.split("::")[2] + end + end + end +end diff --git a/lib/ats/cli/threat_grid.rb b/lib/ats/cli/threat_grid.rb deleted file mode 100644 index 0ba8aae..0000000 --- a/lib/ats/cli/threat_grid.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'ats/cli/threat_grid/command' -require 'ats/cli/threat_grid/organizations' -require 'ats/cli/threat_grid/samples' -require 'ats/cli/threat_grid/search' -require 'ats/cli/threat_grid/users' -require 'ats/cli/threat_grid/whoami' - -require 'ats/cli/threat_grid/application' - -module ATS - module CLI - module ThreatGrid - end - end -end diff --git a/lib/ats/cli/threat_grid/command.rb b/lib/ats/cli/threat_grid/command.rb deleted file mode 100644 index 915712d..0000000 --- a/lib/ats/cli/threat_grid/command.rb +++ /dev/null @@ -1,26 +0,0 @@ -module ATS - module CLI - module ThreatGrid - class Command < Thor - class_option :profile, default: :default, required: false - - def self.printable_commands(*args) - super.map do |x| - x[0] = x[0].gsub(/^ats/, 'ats threatgrid') - x - end - end - - protected - - def api - ATS::ThreatGrid::API.new(profile: options['profile']) - end - - def print_json(json) - say JSON.pretty_generate(json), :green - end - end - end - end -end |
