lib/awskeyring_command.rb in awskeyring-0.1.0 vs lib/awskeyring_command.rb in awskeyring-0.1.1

- old
+ new

@@ -8,15 +8,17 @@ # AWSkeyring command line interface. class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength map %w[--version -v] => :__version map ['init'] => :initialise + map ['con'] => :console map ['ls'] => :list map ['lsr'] => :list_role map ['rm'] => :remove map ['rmr'] => :remove_role map ['rmt'] => :remove_token + map ['rot'] => :rotate desc '--version, -v', 'Prints the version' # print the version number def __version puts Awskeyring::VERSION @@ -187,11 +189,21 @@ def token(account = nil, role = nil, code = nil) # rubocop:disable all account = ask_check( existing: account, message: 'account name', validator: Awskeyring::Validate.method(:account_name) ) role ||= options[:role] + if role + role = ask_check( + existing: role, message: 'role name', validator: Awskeyring::Validate.method(:role_name) + ) + end code ||= options[:code] + if code + code = ask_check( + existing: code, message: 'current mfa code', validator: Awskeyring::Validate.method(:mfa_code) + ) + end duration = options[:duration] duration ||= (60 * 60 * 1).to_s if role duration ||= (60 * 60 * 12).to_s if code if !role && !code @@ -256,27 +268,31 @@ unless comp_line exec_name = File.basename($PROGRAM_NAME) warn "enable autocomplete with 'complete -C /path-to-command/#{exec_name} #{exec_name}'" exit 1 end - comp_len = comp_line.split.length - comp_len += 1 if curr == '' + comp_len = comp_line.split.index(prev) - comp_len = 2 if prev == 'help' - comp_len = 4 if prev == 'remove-role' + case prev + when 'help' + comp_len = 0 + when 'remove-role', '-r', 'rmr' + comp_len = 2 + end + print_auto_resp(curr, comp_len) end private def print_auto_resp(curr, len) case len - when 2 + when 0 puts list_commands.select { |elem| elem.start_with?(curr) }.join("\n") - when 3 + when 1 puts Awskeyring.list_account_names.select { |elem| elem.start_with?(curr) }.join("\n") - when 4 + when 2 puts Awskeyring.list_role_names.select { |elem| elem.start_with?(curr) }.join("\n") else exit 1 end end @@ -313,9 +329,10 @@ begin value = ask_missing(existing: existing, message: message, secure: secure, optional: optional) value = validator.call(value) unless value.empty? && optional rescue RuntimeError => e warn e.message + existing = nil retry unless (retries -= 1).zero? exit 1 end value end