15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# 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
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
|