Class: Nugrant::Vagrant::V2::Command::Env
- Inherits:
-
Object
- Object
- Nugrant::Vagrant::V2::Command::Env
- Defined in:
- lib/nugrant/vagrant/v2/command/env.rb
Instance Method Summary collapse
- #create_parser ⇒ Object
- #execute ⇒ Object
- #help(parser) ⇒ Object
-
#initialize(arguments, environment) ⇒ Env
constructor
A new instance of Env.
Constructor Details
#initialize(arguments, environment) ⇒ Env
Returns a new instance of Env.
9 10 11 12 13 14 15 |
# File 'lib/nugrant/vagrant/v2/command/env.rb', line 9 def initialize(arguments, environment) super(arguments, environment) @unset = false @script = false @show_help = false end |
Instance Method Details
#create_parser ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nugrant/vagrant/v2/command/env.rb', line 17 def create_parser() return OptionParser.new do |parser| parser. = "Usage: vagrant user env [<options>]" parser.separator "" parser.separator "Outputs the commands that should be executed to export\n" + "the various parameter as environment variables. By default,\n" + "existing ones are overridden." parser.separator "" parser.separator "Available options:" parser.separator "" parser.on("-u", "--[no-]unset", "Generates commands needed to unset environment variables, default false") do |unset| @unset = unset end parser.on("-s", "--[no-]script", "Generates a bash script instead of simply showing command, default false") do |script| @script = script end parser.on("-h", "--help", "Print this help") do @show_help = true end end end |
#execute ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/nugrant/vagrant/v2/command/env.rb', line 48 def execute parser = create_parser() arguments = (parser) return help(parser) if @show_help @logger.debug("Nugrant 'Env'") with_target_vms(arguments) do |vm| config = vm.config.user parameters = config ? config.parameters : Nugrant::Parameters.new() bag = parameters.__all = {:type => @unset ? :unset : :export} Helper::Env.write_commands(bag, ) if not @script Helper::Env.write_script(bag, ) if @script # No need to execute for the other VMs return 0 end end |
#help(parser) ⇒ Object
44 45 46 |
# File 'lib/nugrant/vagrant/v2/command/env.rb', line 44 def help(parser) @env.ui.info(parser.help, :prefix => false) end |