Class: Baker::CLI
- Inherits:
-
Object
- Object
- Baker::CLI
- Defined in:
- lib/cli.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
The array of (unparsed) command-line options.
-
#options ⇒ Object
readonly
The hash of (parsed) command-line options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #option_parser ⇒ Object
- #parse_options! ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
14 15 16 |
# File 'lib/cli.rb', line 14 def initialize(args) @args = args.dup end |
Instance Attribute Details
#args ⇒ Object (readonly)
The array of (unparsed) command-line options
10 11 12 |
# File 'lib/cli.rb', line 10 def args @args end |
#options ⇒ Object (readonly)
The hash of (parsed) command-line options
12 13 14 |
# File 'lib/cli.rb', line 12 def @options end |
Class Method Details
.run(args) ⇒ Object
3 4 5 6 7 |
# File 'lib/cli.rb', line 3 def self.run(args) cli = new(args) cli. cli.run end |
Instance Method Details
#option_parser ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cli.rb', line 18 def option_parser # @logger = Logger.new @option_parser ||= OptionParser.new do |opts| opts. = "Usage: #{File.basename($0)} <server>" opts.on("-s", "--setup", "sets up chef, must be ran once before you can run chef recipes.") do [:setup] = true end opts.on("-h", "--help", "Display this help message.") do puts opts exit end opts.on("-V", "--version", "Display the baker version, and exit.") do puts "Baker Version #{Baker::Version}" exit end end end |
#parse_options! ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cli.rb', line 39 def # defaults @options = {:host => '', :setup => false} if args.empty? warn "Please specifiy the server to run the recipes on." warn option_parser exit 1 end option_parser.parse!(args) [:host].concat(*args) end |