Class: SSH::Manager::Client
- Inherits:
-
Object
- Object
- SSH::Manager::Client
- Defined in:
- lib/ssh/manager/client.rb
Constant Summary collapse
- CODES =
%w[iso-2022-jp shift_jis euc-jp utf8 binary]- CODE_ALIASES =
{ "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #execute! ⇒ Object
- #extract_options ⇒ Object
-
#initialize(argv) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(argv) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 |
# File 'lib/ssh/manager/client.rb', line 15 def initialize(argv) = {} @argv = argv end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/ssh/manager/client.rb', line 11 def end |
Instance Method Details
#execute! ⇒ Object
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ssh/manager/client.rb', line 22 def execute! cli = SSH::Manager::Cli # TODO id.to_i is not good enough. we want to support hostnames too # Checking and casting in the methods itself could solve the problem # futhermore this could reside in a separate method if [:add] puts 'Adding ..' cli.new().add_connection elsif [:connect] puts 'Connecting ..' cli.new().connect_to([:connect]) elsif [:info] puts 'Printing info ..' cli.new().show_info([:info]) elsif [:execute] puts 'Executing command..' cli.new().execute_command([:execute]) elsif [:transfer_file] puts 'Transfering file..' cli.new().transfer_file([:transfer_file].to_i, @argv[2], @argv[3]) elsif [:ping] puts 'Pinging..' cli.new().ping([:ping]) elsif [:delete] puts 'Deleting ..' cli.new().delete([:delete]) elsif [:list] puts 'Listing ..' cli.new().list_all elsif [:upgrade] puts 'Checking for new updates ..' cli.new().update_available elsif [:update] puts 'Updating ..' cli.new().update([:update]) elsif [:multi] puts 'Connecting to multiple ips..' cli.new().multiple_connection([:multi]) elsif [:transfer_key] puts 'Transfering key..' cli.new().transfer_key([:transfer_key]) elsif [:encoding] puts 'coding key..' cli.new().test([:encoding].to_i) elsif [:settings] puts 'Settings' cli.new().settings elsif [:search] puts 'Searching ..' cli.new().search_for([:search]) else if @argv.count == 1 cli.new().connect_to(@argv.first.split(',')) if @argv != [] else cli.new().connect_to(@argv) if @argv != [] end puts @optparse if @argv ==[] exit end end |
#extract_options ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/ssh/manager/client.rb', line 83 def begin @optparse = OptionParser.new do |opts| opts. = "Usage: sshm [options] ..." [:add] = false opts.on( '-a', '--add', 'add a new connection' ) do [:add] = true end [:transfer_key] = false opts.on( '-t', '--transferkey id,id,id', Array, 'transfer key to <id>' ) do |opt| [:transfer_key] = opt end [:transfer_file] = false opts.on( '-r', '--transferfile filename', 'file or dir / connection_ID / dest_path(default is /home/user/)' ) do |opt| [:transfer_file] = opt end [:encoding] = false code_list = (CODE_ALIASES.keys + CODES).join(',') opts.on("--code CODE", CODES, CODE_ALIASES, "Select encoding"," (#{code_list})") do |encoding| [:encoding] = encoding end [:connect] = false opts.on( '-c', '--connect id1, id2, id3', Array, 'connect to <ids>' ) do |opt| [:connect] = opt end [:info] = false opts.on( '-i', '--info id1 id2 id3',Array, 'info about to <id>' ) do |opt| [:info] = opt end [:execute] = false opts.on( '-x', '--exec id1 id2 id3',Array, 'exec command on <id>' ) do |opt| [:execute] = opt end [:ping] = false opts.on( '-p', '--ping id1, id2, i3', Array, 'test connection of <id>' ) do |opt| [:ping] = opt end [:delete] = false opts.on( '-d', '--delete id1 id2 id3',Array, 'delete connection <ids>' ) do |opt| [:delete] = opt end [:update] = false opts.on( '-u', '--update id,id,id',Array ,'update connection <id>' ) do |opt| [:update] = opt end [:search] = false opts.on( '-s', '--search string', 'search connection for given criteria' ) do |opt| [:search] = opt end [:multi] = false opts.on( '-m', '--multi searchterm', 'connect to multiple ips with given criteria' ) do |opt| [:multi] = opt end [:list] = false opts.on( '-l', '--list', 'list all connections' ) do [:list] = true end [:upgrade] = false opts.on( '-g', '--upgrade', 'checks for upgrade' ) do [:upgrade] = true end [:settings] = false opts.on( '--settings', 'update settings' ) do [:settings] = true end opts.on( '-h', '--help', 'display this screen' ) do puts opts exit end opts.on( '-v', '--version', 'print programs version' ) do puts SSH::Manager::VERSION exit end end @optparse.parse(@argv) rescue => e catch "That didnt work: #{e.to_s}" end end |