Class: Nugrant::Vagrant::V2::Command::Parameters
- Inherits:
-
Object
- Object
- Nugrant::Vagrant::V2::Command::Parameters
- Defined in:
- lib/nugrant/vagrant/v2/command/parameters.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all(parameters) ⇒ Object
- #create_parser ⇒ Object
- #defaults(parameters) ⇒ Object
- #execute ⇒ Object
- #help(parser) ⇒ Object
-
#initialize(arguments, environment) ⇒ Parameters
constructor
A new instance of Parameters.
- #print_bag(kind, bag) ⇒ Object
- #print_header(kind, length = 50) ⇒ Object
- #print_parameters(kind, hash) ⇒ Object
- #print_warning(used_restricted_keys) ⇒ Object
- #project(parameters) ⇒ Object
- #system(parameters) ⇒ Object
- #user(parameters) ⇒ Object
Constructor Details
#initialize(arguments, environment) ⇒ Parameters
Returns a new instance of Parameters.
14 15 16 17 18 19 20 21 22 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 14 def initialize(arguments, environment) super(arguments, environment) @show_help = false @show_defaults = false @show_system = false @show_user = false @show_project = false end |
Class Method Details
.synopsis ⇒ Object
10 11 12 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 10 def self.synopsis "prints parameters hierarchy as seen by Nugrant" end |
Instance Method Details
#all(parameters) ⇒ Object
107 108 109 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 107 def all(parameters) print_bag("All", parameters.__all) end |
#create_parser ⇒ Object
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 53 54 55 56 57 58 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 24 def create_parser() return OptionParser.new do |parser| parser. = "Usage: vagrant user parameters [<options>]" parser.separator "" parser.separator "Available options:" parser.separator "" parser.on("-h", "--help", "Prints this help") do @show_help = true end parser.on("-d", "--defaults", "Show only defaults parameters") do @show_defaults = true end parser.on("-s", "--system", "Show only system parameters") do @show_system = true end parser.on("-u", "--user", "Show only user parameters") do @show_user = true end parser.on("-p", "--project", "Show only project parameters") do @show_project = true end parser.separator "" parser.separator "When no options is provided, the command prints the names and values \n" + "of all parameters that would be available for usage in the Vagrantfile.\n" + "The hierarchy of the parameters is respected, so the final values are\n" + "displayed." end end |
#defaults(parameters) ⇒ Object
91 92 93 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 91 def defaults(parameters) print_bag("Defaults", parameters.__defaults) end |
#execute ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 60 def execute parser = create_parser() arguments = (parser) return help(parser) if @show_help @logger.debug("'Parameters' each target VM...") with_target_vms(arguments) do |vm| parameters = vm.config.user if not parameters @env.ui.info("# Vm '#{vm.name}' : unable to retrieve `config.user`, report as bug https://github.com/maoueh/nugrant/issues", :prefix => false) next end @env.ui.info("# Vm '#{vm.name}'", :prefix => false) defaults(parameters) if @show_defaults system(parameters) if @show_system user(parameters) if @show_user project(parameters) if @show_project all(parameters) if !@show_defaults && !@show_system && !@show_user && !@show_project end return 0 end |
#help(parser) ⇒ Object
87 88 89 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 87 def help(parser) @env.ui.info(parser.help, :prefix => false) end |
#print_bag(kind, bag) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 111 def print_bag(kind, bag) if !bag || bag.empty?() print_header(kind) @env.ui.info(" Empty", :prefix => false) @env.ui.info("", :prefix => false) return end print_parameters(kind, { 'config' => { 'user' => bag.to_hash(:use_string_key => true) } }) end |
#print_header(kind, length = 50) ⇒ Object
137 138 139 140 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 137 def print_header(kind, length = 50) @env.ui.info(" #{kind.capitalize} Parameters", :prefix => false) @env.ui.info(" " + "-" * length, :prefix => false) end |
#print_parameters(kind, hash) ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 126 def print_parameters(kind, hash) string = Nugrant::Helper::Yaml.format(hash.to_yaml, :indent => 1) used_restricted_keys = Helper::get_used_restricted_keys(hash, Helper::get_restricted_keys()) print_warning(used_restricted_keys) if !used_restricted_keys.empty?() print_header(kind) @env.ui.info(string, :prefix => false) @env.ui.info("", :prefix => false) end |
#print_warning(used_restricted_keys) ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 142 def print_warning(used_restricted_keys) @env.ui.info("", :prefix => false) @env.ui.info(" You are using some restricted keys. Method access (using .<key>) will", :prefix => false) @env.ui.info(" not work, only array access ([<key>]) will. Offending keys:", :prefix => false) @env.ui.info(" #{used_restricted_keys.join(", ")}", :prefix => false) @env.ui.info("", :prefix => false) end |
#project(parameters) ⇒ Object
103 104 105 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 103 def project(parameters) print_bag("Project", parameters.__current) end |
#system(parameters) ⇒ Object
95 96 97 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 95 def system(parameters) print_bag("System", parameters.__system) end |
#user(parameters) ⇒ Object
99 100 101 |
# File 'lib/nugrant/vagrant/v2/command/parameters.rb', line 99 def user(parameters) print_bag("User", parameters.__user) end |