Module: Flare::Tools::Cli::Option

Includes:
Util::Constant
Included in:
Dispatch, SubCommand
Defined in:
lib/flare/tools/cli/option.rb

Constant Summary

Constants included from Util::Constant

Util::Constant::DefalutBwlimit, Util::Constant::DefaultIndexServerName, Util::Constant::DefaultIndexServerPort, Util::Constant::DefaultNodePort, Util::Constant::DefaultTimeout, Util::Constant::STATUS_NG, Util::Constant::STATUS_OK

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optpObject (readonly)

Returns the value of attribute optp.



10
11
12
# File 'lib/flare/tools/cli/option.rb', line 10

def optp
  @optp
end

Instance Method Details

#option_initObject



12
13
14
# File 'lib/flare/tools/cli/option.rb', line 12

def option_init
  @optp = OptionParser.new
end

#parse_options(config, argv) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/flare/tools/cli/option.rb', line 45

def parse_options(config, argv)
  begin
    rest = @optp.parse(argv)
  rescue OptionParser::ParseError => err
    puts err.message
    puts @optp.to_s
    exit STATUS_NG
  end
  rest
end

#set_option_dry_runObject



35
36
37
38
# File 'lib/flare/tools/cli/option.rb', line 35

def set_option_dry_run
  @dry_run ||= false
  @optp.on('-n',          '--dry-run',                "dry run") { @dry_run = true }
end

#set_option_forceObject



40
41
42
43
# File 'lib/flare/tools/cli/option.rb', line 40

def set_option_force
  @force ||= false
  @optp.on('--force', "commit changes without confirmation") { @force = true }
end

#set_option_globalObject



16
17
18
19
20
21
22
23
24
# File 'lib/flare/tools/cli/option.rb', line 16

def set_option_global
  @optp.on('-h',        '--help',     "show this message") { puts @optp.help; exit 1 }
  @optp.on(             '--debug',    "enable debug mode") { $DEBUG = true }
  @optp.on(             '--warn',     "turn on warnings")  { $-w = true }
  @optp.on(             '--log-file=LOGFILE',       "output log to LOGFILE") {|v| Flare::Util::Logging.set_logger(v)}

  @timeout ||= DefaultTimeout
  @optp.on(             '--timeout=SECOND',         "specify timeout") {|v| @timeout = v.to_i}
end

#set_option_index_serverObject



26
27
28
29
30
31
32
33
# File 'lib/flare/tools/cli/option.rb', line 26

def set_option_index_server
  @index_server_entity ||= Flare::Entity::Server.new(nil, nil)
  @cluster ||= nil

  @optp.on('-i HOSTNAME', '--index-server=HOSTNAME',  "index server hostname(default:#{DefaultIndexServerName})") {|v| @index_server_host = v}
  @optp.on('-p PORT',     '--index-server-port=PORT', "index server port(default:#{DefaultIndexServerPort})") {|v| @index_server_port = v.to_i}
  @optp.on(               '--cluster=NAME',           "specify a cluster name") {|v| @cluster = v}
end