Class: Ceph::Crush::Location::Options::Parser
- Inherits:
-
Object
- Object
- Ceph::Crush::Location::Options::Parser
- Defined in:
- lib/ceph/crush/location/options/parser.rb
Overview
Parses it
Class Method Summary collapse
- .default_env ⇒ Object
- .env! ⇒ Object
- .grab! ⇒ Object
- .options(opts) ⇒ Object
- .parse! ⇒ Object
- .report(e) ⇒ Object
- .tail ⇒ Object
- .usage(opts) ⇒ Object
- .validate! ⇒ Object
Class Method Details
.default_env ⇒ Object
26 27 28 29 30 |
# File 'lib/ceph/crush/location/options/parser.rb', line 26 def default_env Ceph::Crush::Location::Logger.send('Options::Parser.default_env') ::Ceph::Crush::Location.[:nodeinfo] = '/etc/nodeinfo/info.json' end |
.env! ⇒ Object
32 33 34 35 36 |
# File 'lib/ceph/crush/location/options/parser.rb', line 32 def env! Ceph::Crush::Location::Logger.send('Options::Parser.env!') return unless ENV['NODE_INFO'] ::Ceph::Crush::Location.[:nodeinfo] = ENV['NODE_INFO'] end |
.grab! ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ceph/crush/location/options/parser.rb', line 79 def grab! Ceph::Crush::Location::Logger.send('Options::Parser.grab!') OptionParser.new do |opts| usage(opts) (opts) opts.separator '' opts.separator 'Common options:' end.parse!(ARGV) end |
.options(opts) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ceph/crush/location/options/parser.rb', line 51 def (opts) Ceph::Crush::Location::Logger.send('Options::Parser.options') opts.on('-c', '--cluster CLUSTER', 'Specify Cluster Name') do |c| ::Ceph::Crush::Location.[:cluster] = c end opts.on('-t', '--type TYPE', 'Specify Daemon Type') do |t| ::Ceph::Crush::Location.[:type] = t end opts.on('-i', '--id ID', 'Specify Daemon ID') do |i| ::Ceph::Crush::Location.[:id] = i end end |
.parse! ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ceph/crush/location/options/parser.rb', line 14 def parse! ::Ceph::Crush::Location::Logger.send('parsing attributes') ::Ceph::Crush::Location. = {} grab! validate! default_env env! ::Ceph::Crush::Location..freeze rescue OptionParser::MissingArgument => e report e end |
.report(e) ⇒ Object
38 39 40 41 42 |
# File 'lib/ceph/crush/location/options/parser.rb', line 38 def report(e) ::Ceph::Crush::Location::Logger.send(e, Logger::ERROR) STDERR.puts "#{$PROGRAM_NAME}: #{e}" exit(-1) end |
.tail ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ceph/crush/location/options/parser.rb', line 66 def tail Ceph::Crush::Location::Logger.send('Options::Parser.tail') opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end opts.on_tail('--version', 'Show version') do puts Ceph::Crush::Location::VERSION exit end end |
.usage(opts) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/ceph/crush/location/options/parser.rb', line 44 def usage(opts) Ceph::Crush::Location::Logger.send('Options::Parser.usage') opts. = "Usage: #{$PROGRAM_NAME} [options]" opts.separator '' opts.separator 'Specific options:' end |
.validate! ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ceph/crush/location/options/parser.rb', line 91 def validate! Ceph::Crush::Location::Logger.send('Options::Parser.validate!') ::Ceph::Crush::Location..fetch(:cluster) do raise OptionParser::MissingArgument, 'no \'cluster\' provided' end ::Ceph::Crush::Location..fetch(:id) do raise OptionParser::MissingArgument, 'no \'id\' provided' end ::Ceph::Crush::Location..fetch(:type) do raise OptionParser::MissingArgument, 'no \'type\' provided' end end |