Class: VMC::Cli::Command::Micro
- Inherits:
-
Base
show all
- Defined in:
- lib/cli/commands/micro.rb
Constant Summary
Constants inherited
from Base
Base::MANIFEST
Instance Attribute Summary
Attributes inherited from Base
#no_prompt, #prompt_ok
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#auth_token, #client, #client_info, #default_infra, #find_in_hash, #find_symbol, #frameworks_info, #load_manifest, #load_manifest_structure, #manifest, #manifest_file, #merge_manifest, #merge_parent, #resolve_in, #resolve_lexically, #resolve_manifest, #resolve_symbol, #runtimes_info, #target_base, #target_url
Constructor Details
#initialize(args) ⇒ Micro
Returns a new instance of Micro.
4
5
6
|
# File 'lib/cli/commands/micro.rb', line 4
def initialize(args)
super(args)
end
|
Class Method Details
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/cli/commands/micro.rb', line 101
def self.platform
case RUBY_PLATFORM
when /darwin/ :darwin
when /linux/ :linux
when /mingw|mswin32|cygwin/ :windows
else
RUBY_PLATFORM
end
end
|
Instance Method Details
#build_config ⇒ Object
Returns the configuration needed to run the micro related subcommands. First loads saved config from file (if there is any), then overrides loaded values with command line arguments, and finally tries to guess in case neither was used:
vmx location of micro.vmx file
vmrun location of vmrun command
password password for vcap user (in the guest vm)
platform current platform
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/cli/commands/micro.rb', line 49
def build_config
conf = VMC::Cli::Config.micro
override(conf, 'vmx', true) do
locate_vmx(Micro.platform)
end
override(conf, 'vmrun', true) do
VMC::Micro::VMrun.locate(Micro.platform)
end
override(conf, 'password') do
@password = ask("Please enter your Micro Cloud Foundry VM password (vcap user) password", :echo => "*")
end
conf['platform'] = Micro.platform
conf
end
|
#command(cmd) ⇒ Object
20
21
22
23
24
|
# File 'lib/cli/commands/micro.rb', line 20
def command(cmd)
config = build_config
switcher(config).send(cmd)
store_config(config)
end
|
#locate_vmx(platform) ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/cli/commands/micro.rb', line 93
def locate_vmx(platform)
paths = YAML.load_file(VMC::Micro.config_file('paths.yml'))
vmx_paths = paths[platform.to_s]['vmx']
vmx = VMC::Micro.locate_file('micro.vmx', 'micro', vmx_paths)
err "Unable to locate micro.vmx, please supply --vmx option" unless vmx
vmx
end
|
#offline(mode) ⇒ Object
8
9
10
|
# File 'lib/cli/commands/micro.rb', line 8
def offline(mode)
command('offline')
end
|
#online(mode) ⇒ Object
12
13
14
|
# File 'lib/cli/commands/micro.rb', line 12
def online(mode)
command('online')
end
|
#override(config, option, escape = false, &blk) ⇒ Object
override with command line arguments and yield the block in case the option isn’t set
84
85
86
87
88
89
90
91
|
# File 'lib/cli/commands/micro.rb', line 84
def override(config, option, escape=false, &blk)
if opt = @options[option.to_sym]
opt = VMC::Micro.escape_path(opt) if escape
config[option] = opt
end
config[option] = yield unless config[option]
end
|
#status(mode) ⇒ Object
16
17
18
|
# File 'lib/cli/commands/micro.rb', line 16
def status(mode)
command('status')
end
|
#store_config(config) ⇒ Object
Save the cleartext password if –save is supplied. Note: it is due to vix we have to use a cleartext password :( Only if –password is used and not –save is the password deleted from the config file before it is stored to disk.
73
74
75
76
77
78
79
80
81
|
# File 'lib/cli/commands/micro.rb', line 73
def store_config(config)
if @options[:save]
warn("cleartext password saved in: #{VMC::Cli::Config::MICRO_FILE}")
elsif @options[:password] || @password
config.delete('password')
end
VMC::Cli::Config.store_micro(config)
end
|