Class: CloudInfo::CLI
- Inherits:
-
Object
- Object
- CloudInfo::CLI
- Defined in:
- lib/cloud_info/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
-
#extract_environment_variables! ⇒ Object
Extracts name=value pairs from the remaining command-line arguments and assigns them as environment variables.
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
-
#option_parser ⇒ Object
Return an OptionParser instance that defines the acceptable command line switches for cloud_info, and what their corresponding behaviors are.
- #parse_options! ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
19 20 21 |
# File 'lib/cloud_info/cli.rb', line 19 def initialize(args) @args = args.dup end |
Instance Attribute Details
#args ⇒ Object (readonly)
The array of (unparsed) command-line options
15 16 17 |
# File 'lib/cloud_info/cli.rb', line 15 def args @args end |
#options ⇒ Object (readonly)
The hash of (parsed) command-line options
17 18 19 |
# File 'lib/cloud_info/cli.rb', line 17 def @options end |
Class Method Details
.run(args) ⇒ Object
8 9 10 11 12 |
# File 'lib/cloud_info/cli.rb', line 8 def self.run(args) cli = new(args) cli. cli.run end |
Instance Method Details
#extract_environment_variables! ⇒ Object
Extracts name=value pairs from the remaining command-line arguments and assigns them as environment variables.
73 74 75 76 77 78 |
# File 'lib/cloud_info/cli.rb', line 73 def extract_environment_variables! #:nodoc: args.delete_if do |arg| next unless arg.match(/^(\w+)=(.*)$/) ENV[$1] = $2 end end |
#option_parser ⇒ Object
Return an OptionParser instance that defines the acceptable command line switches for cloud_info, and what their corresponding behaviors are.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cloud_info/cli.rb', line 26 def option_parser # @logger = Logger.new @option_parser ||= OptionParser.new do |opts| opts. = "Usage: #{File.basename($0)} [options] action ..." opts.on("-d", "--debug", "Debug mode, more output" ) { |value| [:debug] = true } opts.on("-u", "--user USER", "ssh user" ) { |value| [:user] = value } opts.on("-h", "--help", "Display this help message.") do puts opts exit end opts.on("-V", "--version", "Display the cloud_info version, and exit." ) do require 'cloud_info/version' puts "CloudInfo v#{CloudInfo::Version}" exit end end end |
#parse_options! ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cloud_info/cli.rb', line 55 def @options = {:actions => []} if args.empty? warn "Please specifiy an action to execute." warn option_parser exit 1 end option_parser.parse!(args) coerce_variable_types! extract_environment_variables! [:actions].concat(args) end |
#run ⇒ Object
80 81 82 83 |
# File 'lib/cloud_info/cli.rb', line 80 def run puts "TODO FINISH LOGIC" pp end |