class PDO::Opts
Public Class Methods
parse(args, opts)
click to toggle source
# File lib/pdo/opts.rb, line 7 def self.parse(args, opts) op = OptionParser.new op.set_summary_width 15 op.banner = "pdo [opts]" op.separator "" op.separator "Specific options:" op.on('-c CMD', 'the command to be executed', "if CMD equals to '-', then read command from stdin") do |cmd| if cmd == '-' then opts.cmd = $stdin.read else opts.cmd = cmd end end op.on('--count', 'count the number of hosts') do |count| opts.count = true end op.on('--enum', 'enumerate the hosts') do |enum| opts.enum = true end op.on('-f <name>', 'name of the alternative host definition file') do |fn| opts.host_definition_file = fn end op.on('-g <name1,name2,...>', Array, 'comma separated group or host names') do |groups| opts.groups = groups end op.on('-l', 'run the command CMD locally') do opts.local = true end op.on('--step <m,n>', Array, 'stepping the hosts, m and n must be integers;', 'if n > 0, stepping forward; if n < 0 stepping', 'backward') do |step| opts.step = [step[0].to_i, step[1].to_i] end op.on('--sshopts <key1=val1,key2=val2,...>', Array, 'ssh options as described in "man ssh_config"') do |sshopts| opts.sshopts = {} unless opts.sshopts sshopts.each do |opt| key, val = opt.split '=' opts.sshopts[:"#{key}"] = val if key and val end end op.on('-t INTEGER', Integer, 'number of threads') do |thread_num| if thread_num < 0 then raise ArgumentError, "thread number must be greater or equal to zero" end opts.thread_num = thread_num end op.on('-x <name1,name2,...>', Array, 'comma separated group or host names, which should be', 'excluded from the final list') do |e_groups| opts.e_groups = e_groups end op.on('-y', 'do not confirm, execute immediately') do opts.confirm_before_execute = false end op.separator "" op.separator "Common options:" op.on_tail('-h', '--help', 'this help') do puts op.help exit 0 end op.parse!(args) return opts end