Class: TinysshOptparse

Inherits:
Object
  • Object
show all
Defined in:
lib/tinysshoptparse.rb

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tinysshoptparse.rb', line 5

def self.parse(args)
  options = OpenStruct.new
  options.user        = 'root'
  options.port        = '22'
  options.num         = '0'
  options.keys        = ['/root/.ssh/id_rsa']
  options.timeout     = 5
  options.host_file   = nil
  options.output_file = nil

  opts = OptionParser.new do |opts|
    opts.banner = "\nUsage: tinyssh.rb run|upload|download <position parameters> [option]"

    opts.separator ""
    opts.separator "Specific options:"

    opts.on("-u", "--user [user]",
            "Specify a user for accessing remote hosts.(default: root)") do |user|
      options.user = user
    end

    opts.on("-p", "--port [port]",
            "Port to connect to on the remote host(default: 22)") do |port|
      options.port = port
    end

    opts.on("-t", "--timeout [time]",
            "Set the command timeout to seconds(default: 0)") do |timeout|
      options.timeout = timeout.to_i
    end

    opts.on("-l", "--list-file [file]",
            "File containing a list of hosts' IP Address") do |file|
      options.host_file = file
    end

    opts.on("-o", "--output-file [file]",
            "Output result to log file") do |output_file|
      options.output_file = output_file
    end

    opts.on("-i", "--identity-keys [keys]",
            "identity (private) keys for authentication(default: /root/.ssh/id_rsa)") do |keys|
      options.keys = keys
    end

    opts.on("-n", "--number-of-thread [number]",
            "Specify the number of concurrent jobs for each execution") do |num|
      options.num = num
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end

  opts.parse!(args)
  options
end