Class: Topo::Provision::CLI
- Inherits:
-
Object
- Object
- Topo::Provision::CLI
- Includes:
- Mixlib::CLI
- Defined in:
- lib/topo/provision/cli.rb
Instance Attribute Summary collapse
-
#topology ⇒ Object
Returns the value of attribute topology.
Instance Method Summary collapse
-
#initialize(argv = []) ⇒ CLI
constructor
A new instance of CLI.
- #parse_and_validate_args ⇒ Object
- #redirect_stdout(file) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(argv = []) ⇒ CLI
Returns a new instance of CLI.
48 49 50 51 |
# File 'lib/topo/provision/cli.rb', line 48 def initialize(argv=[]) super() parse_and_validate_args end |
Instance Attribute Details
#topology ⇒ Object
Returns the value of attribute topology.
46 47 48 |
# File 'lib/topo/provision/cli.rb', line 46 def topology @topology end |
Instance Method Details
#parse_and_validate_args ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/topo/provision/cli.rb', line 53 def parse_and_validate_args begin @input_file = cli_arguments()[0] rescue OptionParser::InvalidOption => e STDERR.puts e. puts opt_parser exit(-1) end if !@input_file STDERR.puts opt_parser exit(-1) end end |
#redirect_stdout(file) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/topo/provision/cli.rb', line 69 def redirect_stdout(file) begin $stdout.reopen(file, "w") rescue => e STDERR.puts "ERROR: Cannot open provisioning output file #{file} - #{e.}" end end |
#run ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/topo/provision/cli.rb', line 77 def run @topology = Topo::Loader.from_file(@input_file, @config[:format] || "default") # output topo file @topology.to_file(@config[:output_topo]) if(@config[:output_topo]) # redirect generated recipe to file redirect_stdout(@config[:output]) if(@config[:output]) # run generator @generator = Topo::Provision::Generator.new(@topology) action = @config[:action].to_sym @generator.generate_provisioning_recipe(action) end |