Class: SchemaTransformer::CLI
- Inherits:
-
Object
- Object
- SchemaTransformer::CLI
- Defined in:
- lib/schema_transformer/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
Returns a new instance of CLI.
17 18 19 |
# File 'lib/schema_transformer/cli.rb', line 17 def initialize(args) @args = args.dup end |
Instance Attribute Details
#args ⇒ Object (readonly)
The array of (unparsed) command-line options
13 14 15 |
# File 'lib/schema_transformer/cli.rb', line 13 def args @args end |
#options ⇒ Object (readonly)
The hash of (parsed) command-line options
15 16 17 |
# File 'lib/schema_transformer/cli.rb', line 15 def @options end |
Class Method Details
.run(args) ⇒ Object
6 7 8 9 10 |
# File 'lib/schema_transformer/cli.rb', line 6 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.
72 73 74 75 76 77 |
# File 'lib/schema_transformer/cli.rb', line 72 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.
24 25 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 |
# File 'lib/schema_transformer/cli.rb', line 24 def option_parser # @logger = Logger.new @option_parser ||= OptionParser.new do |opts| opts. = "Usage: #{File.basename($0)} [options] [action]" opts.on("-h", "--help", "Display this help message.") do puts puts opts exit end opts.on("-v", "--verbose", "Verbose mode" ) { |value| [:verbose] = true } opts.on("-s", "--stagger [VALUE]", "Number of seconds to wait inbetween each bulk insert. Default 0" ) { |value| [:stagger] = value } opts.on("-V", "--version", "Display the schema_transformer version, and exit." ) do require File.("../version", __FILE__) puts "Schema Transformer v#{SchemaTransformer::VERSION}" exit end end end |
#parse_options! ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/schema_transformer/cli.rb', line 54 def @options = {:action => nil} if args.empty? warn "Please specifiy an action to execute." warn warn option_parser exit 1 end option_parser.parse!(args) extract_environment_variables! [:action] = args # ignore remaining end |
#run ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/schema_transformer/cli.rb', line 79 def run @action = [:action].first if @action == "analyze" SchemaTransformer::Analyze.run() else begin SchemaTransformer::Transform.run() rescue UsageError => e puts "Usage Error: #{e.}" puts puts option_parser end end end |