class SshShort::CLI
Public Class Methods
add_options_if_present(node, args, options)
click to toggle source
# File lib/ssh_short/cli.rb, line 53 def self.add_options_if_present(node, args, options) options.each { |option| node[option] = args[option] if args.include?(option) } node end
run(argv)
click to toggle source
# File lib/ssh_short/cli.rb, line 15 def self.run(argv) config = SshShort::Parser.parse_config args = SshShort::Parser.parse_input(config, argv) key_set = SshShort::KeySet.new(config[:keys_dir]) node_mapper = SshShort::NodeMapper.new if args[:action] == :list_aliases node_mapper.get_aliases.each { |node_alias| puts node_alias } exit end node = node_mapper.get_node args[:node] node ||= {:host => args[:node]} if node[:key].nil? or args[:force_key_prompt] node[:key] = key_set.prompt_for_key end if node[:user].nil? abort 'No user was provided and no default is set' unless config[:default_user] node[:user] = config[:default_user] end node = CLI.add_options_if_present(node, args, [:alias, :user]) node_mapper.update_node(node) key_path = key_set.get_key node[:key] case args[:action] when :connect Connection.connect node[:host], node[:user], key_path when :push Connection.push node[:host], node[:user], key_path, args[:source], args[:target] when :pull Connection.pull node[:host], node[:user], key_path, args[:source], args[:target] else abort 'Unknown action' end end