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
27 28 29 30 31 |
# File 'lib/ceph/crush/location/options/parser.rb', line 27 def default_env Ceph::Crush::Location::Logger.send('Options::Parser.default_env') ::Ceph::Crush::Location.[:nodeinfo] = '/etc/nodeinfo/info.json' end |
.env! ⇒ Object
33 34 35 36 37 |
# File 'lib/ceph/crush/location/options/parser.rb', line 33 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
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ceph/crush/location/options/parser.rb', line 80 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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ceph/crush/location/options/parser.rb', line 52 def (opts) Ceph::Crush::Location::Logger.send('Options::Parser.options') opts.on('-c', '--cluster [CLUSTER]', 'Specify Cluster') 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 25 |
# File 'lib/ceph/crush/location/options/parser.rb', line 14 def parse! ::Ceph::Crush::Location::Logger.send('parsing attributes') ::Ceph::Crush::Location. = {} ::Ceph::Crush::Location.[:cluster] = 'ceph' grab! validate! default_env env! ::Ceph::Crush::Location..freeze rescue OptionParser::MissingArgument => e report e end |
.report(e) ⇒ Object
39 40 41 42 43 |
# File 'lib/ceph/crush/location/options/parser.rb', line 39 def report(e) ::Ceph::Crush::Location::Logger.send(e, ::Logger::ERROR) STDERR.puts "#{$PROGRAM_NAME}: #{e}" exit(-1) end |
.tail ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ceph/crush/location/options/parser.rb', line 67 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
45 46 47 48 49 50 |
# File 'lib/ceph/crush/location/options/parser.rb', line 45 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
92 93 94 95 96 97 98 99 100 |
# File 'lib/ceph/crush/location/options/parser.rb', line 92 def validate! Ceph::Crush::Location::Logger.send('Options::Parser.validate!') ::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 |