Merge pull request #938 from chef/vj/fix-inspec-compliance-login-help

give accurate information for inspec compliance login --help
This commit is contained in:
Christoph Hartmann 2016-08-18 21:01:09 +02:00 committed by GitHub
commit 16ae499d05
4 changed files with 34 additions and 3 deletions

View file

@ -9,8 +9,16 @@ module Compliance
class ComplianceCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength
namespace 'compliance'
desc 'login SERVER', 'Log in to a Chef Compliance SERVER'
option :server, type: :string, desc: 'Chef Compliance Server URL'
# TODO: find another solution, once https://github.com/erikhuda/thor/issues/261 is fixed
def self.banner(command, _namespace = nil, _subcommand = false)
"#{basename} #{subcommand_prefix} #{command.usage}"
end
def self.subcommand_prefix
namespace
end
desc "login SERVER --insecure --user='USER' --token='TOKEN'", 'Log in to a Chef Compliance SERVER'
option :insecure, aliases: :k, type: :boolean,
desc: 'Explicitly allows InSpec to perform "insecure" SSL connections and transfers'
option :user, type: :string, required: false,
@ -41,7 +49,7 @@ module Compliance
elsif !options['refresh_token'].nil?
_success, msg = login_refreshtoken(url, options)
else
puts 'Please run `inspec compliance login` with options --token or --refresh_token and --user'
puts 'Please run `inspec compliance login SERVER` with options --token or --refresh_token, --user, and --insecure or --not-insecure'
exit 1
end

View file

@ -38,6 +38,11 @@ refresh_token = ENV['COMPLIANCE_REFRESHTOKEN']
# submitting a wrong token should have an exit of 0
describe command("#{inspec_bin} compliance login #{api_url} --insecure --user 'admin' --token 'wrong-token'") do
its('stdout') { should include 'token stored' }
end
# compliance login --help should give an accurate message for login
describe command("#{inspec_bin} compliance login --help") do
its('stdout') { should include "inspec compliance login SERVER --insecure --user='USER' --token='TOKEN'" }
its('exit_status') { should eq 0 }
end

View file

@ -7,6 +7,15 @@ module Init
class CLI < Inspec::BaseCLI
namespace 'init'
# TODO: find another solution, once https://github.com/erikhuda/thor/issues/261 is fixed
def self.banner(command, _namespace = nil, _subcommand = false)
"#{basename} #{subcommand_prefix} #{command.usage}"
end
def self.subcommand_prefix
namespace
end
# read template directoy
template_dir = File.join(File.dirname(__FILE__), 'templates')
Dir.glob(File.join(template_dir, '*')) do |template|

View file

@ -6,6 +6,15 @@ module Supermarket
class SupermarketCLI < Inspec::BaseCLI
namespace 'supermarket'
# TODO: find another solution, once https://github.com/erikhuda/thor/issues/261 is fixed
def self.banner(command, _namespace = nil, _subcommand = false)
"#{basename} #{subcommand_prefix} #{command.usage}"
end
def self.subcommand_prefix
namespace
end
desc 'profiles', 'list all available profiles in Chef Supermarket'
def profiles
# display profiles in format user/profile