Class: Supermarket::SupermarketCLI

Inherits:
Inspec::BaseCLI show all
Defined in:
lib/bundles/inspec-supermarket/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Inspec::BaseCLI

check_license!, exec_options, exit_on_failure?, format_platform_info, profile_options, start, target_options

Class Method Details

TODO: find another solution, once github.com/erikhuda/thor/issues/261 is fixed



8
9
10
# File 'lib/bundles/inspec-supermarket/cli.rb', line 8

def self.banner(command, _namespace = nil, _subcommand = false)
  "#{basename} #{subcommand_prefix} #{command.usage}"
end

.subcommand_prefixObject



12
13
14
# File 'lib/bundles/inspec-supermarket/cli.rb', line 12

def self.subcommand_prefix
  namespace
end

Instance Method Details

#exec(*tests) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bundles/inspec-supermarket/cli.rb', line 29

def exec(*tests)
  o = config
  diagnose(o)
  configure_logger(o)

  # iterate over tests and add compliance scheme
  tests = tests.map { |t| "supermarket://" + t }

  runner = Inspec::Runner.new(o)
  tests.each { |target| runner.add_target(target) }

  exit runner.run
rescue ArgumentError, RuntimeError, Train::UserError => e
  $stderr.puts e.message
  exit 1
end

#info(profile) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bundles/inspec-supermarket/cli.rb', line 47

def info(profile)
  # check that the profile is available
  supermarket_profiles = Supermarket::API.profiles
  found = supermarket_profiles.select do |p|
    profile == "#{p['tool_owner']}/#{p['slug']}"
  end

  if found.empty?
    puts "#{mark_text(profile)} is not available on Supermarket"
    return
  end

  # load details for the specific profile
  info = Supermarket::API.info(profile)
  puts "#{mark_text('name: ')}  #{info['slug']}"
  puts "#{mark_text('owner:')}  #{info['owner']}"
  puts "#{mark_text('url:  ')}  #{info['source_url']}"
  puts
  puts "#{mark_text('description:  ')} #{info['description']}"
end

#profilesObject



17
18
19
20
21
22
23
24
25
# File 'lib/bundles/inspec-supermarket/cli.rb', line 17

def profiles
  # display profiles in format user/profile
  supermarket_profiles = Supermarket::API.profiles

  headline("Available profiles:")
  supermarket_profiles.each do |p|
    li("#{p['tool_name']} #{mark_text(p['tool_owner'] + '/' + p['slug'])}")
  end
end