class SafePusher::CLI
Attributes
arguments[R]
Public Class Methods
new(arguments:)
click to toggle source
# File lib/safe_pusher/cli.rb, line 3 def initialize(arguments:) @arguments = arguments end
Public Instance Methods
start()
click to toggle source
# File lib/safe_pusher/cli.rb, line 7 def start return version if arguments.first == '--version' help if commands.include?(nil) commands.compact.each { |command| execute_command(command) } end
Private Instance Methods
available_commands()
click to toggle source
# File lib/safe_pusher/cli.rb, line 54 def available_commands @available_commands ||= ( shortcut_to_command.keys + shortcut_to_command.values ).join('|') end
commands()
click to toggle source
# File lib/safe_pusher/cli.rb, line 30 def commands @commands ||= arguments.map do |arg| next unless arg =~ valid_commands_regexp shortcut_to_command[arg] || arg end end
execute_command(command)
click to toggle source
# File lib/safe_pusher/cli.rb, line 19 def execute_command(command) explain(command) if verbose results = SafePusher::Client .const_get(services[command].capitalize) .new .public_send(command) exit results unless results == 0 end
explain(command)
click to toggle source
# File lib/safe_pusher/cli.rb, line 42 def explain(command) puts I18n.t("command.#{command}.verbose").yellow end
help()
click to toggle source
# File lib/safe_pusher/cli.rb, line 46 def help puts I18n.t('help') end
services()
click to toggle source
# File lib/safe_pusher/cli.rb, line 64 def services @services ||= SafePusher.configuration.services end
shortcut_to_command()
click to toggle source
# File lib/safe_pusher/cli.rb, line 68 def shortcut_to_command @shortcut_to_command ||= YAML .load_file('config/commands.yml') .reduce({}) { |o, (k, v)| o.update(v['shortcut'] => k) } end
valid_commands_regexp()
click to toggle source
# File lib/safe_pusher/cli.rb, line 50 def valid_commands_regexp @valid_commands_regexp ||= /^(?!\s*$)(?:#{available_commands})$/ end
verbose()
click to toggle source
# File lib/safe_pusher/cli.rb, line 60 def verbose @verbose ||= SafePusher.configuration.verbose end
version()
click to toggle source
# File lib/safe_pusher/cli.rb, line 38 def version puts SafePusher::VERSION end