Class: TreasureData::Command::List::CommandParser

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/td/command/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, req_args, opt_args, varlen, argv, req_conn) ⇒ CommandParser

Returns a new instance of CommandParser.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/td/command/list.rb', line 6

def initialize(name, req_args, opt_args, varlen, argv, req_conn)
  super()
  @name = name
  @req_args = req_args
  @opt_args = opt_args
  @varlen = varlen
  @argv = argv
  @has_options = false
  @message = ''
  @cmd_requires_connectivity = req_conn
end

Instance Attribute Details

#argvObject

Returns the value of attribute argv.



18
19
20
# File 'lib/td/command/list.rb', line 18

def argv
  @argv
end

#cmd_requires_connectivityObject

Returns the value of attribute cmd_requires_connectivity.



18
19
20
# File 'lib/td/command/list.rb', line 18

def cmd_requires_connectivity
  @cmd_requires_connectivity
end

#messageObject

Returns the value of attribute message.



18
19
20
# File 'lib/td/command/list.rb', line 18

def message
  @message
end

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/td/command/list.rb', line 18

def name
  @name
end

Instance Method Details



25
26
27
28
29
30
31
32
# File 'lib/td/command/list.rb', line 25

def banner
  s = @message.dup
  if @has_options
    s << "\n"
    s << "options:\n"
  end
  s
end

#cmd_parse(argv = @argv||ARGV) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/td/command/list.rb', line 34

def cmd_parse(argv=@argv||ARGV)
  parse!(argv)
  if argv.length < @req_args.length || (!@varlen && argv.length > (@req_args.length+@opt_args.length))
    cmd_usage nil
  end
  if argv.length <= 1
    return argv[0]
  else
    return argv
  end
rescue
  cmd_usage $!
end

#cmd_usage(msg = nil) ⇒ Object



48
49
50
51
52
# File 'lib/td/command/list.rb', line 48

def cmd_usage(msg=nil)
  $stdout.puts self.to_s
  $stdout.puts "Error: #{msg}" if msg
  exit 1
end

#on(*argv) ⇒ Object



20
21
22
23
# File 'lib/td/command/list.rb', line 20

def on(*argv)
  @has_options = true
  super
end