Module: Milc::Base
Instance Attribute Summary collapse
Instance Method Summary
collapse
#ansible_playbook
#mgcloud
#build_gcloud_command, #gcloud, #json_gcloud
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
42
43
44
|
# File 'lib/milc/base.rb', line 42
def config
@config
end
|
#project ⇒ Object
Returns the value of attribute project.
43
44
45
|
# File 'lib/milc/base.rb', line 43
def project
@project
end
|
Instance Method Details
#command_options ⇒ Object
66
67
68
|
# File 'lib/milc/base.rb', line 66
def command_options
"nVc:"
end
|
#dry_run ⇒ Object
45
46
47
|
# File 'lib/milc/base.rb', line 45
def dry_run
Milc.dry_run
end
|
#execute(cmd, options = {}) ⇒ Object
31
32
33
34
35
|
# File 'lib/milc/base.rb', line 31
def execute(cmd, options = {})
options[:dry_run] = Milc.dry_run
res = LoggerPipe.run(logger, cmd, options)
block_given? ? yield(res) : res
end
|
#help_message ⇒ Object
59
60
61
62
63
64
|
# File 'lib/milc/base.rb', line 59
def help_message
cmdname = File.basename($0)
"Usage: #{cmdname} -c CONF_FILE"
end
|
#load_config ⇒ Object
49
50
51
|
# File 'lib/milc/base.rb', line 49
def load_config
@project = config['PROJECT'] || ENV['PROJECT']
end
|
#load_from_yaml(yaml_path) ⇒ Object
37
38
39
40
|
# File 'lib/milc/base.rb', line 37
def load_from_yaml(yaml_path)
@config = YAML.load_file_with_erb(yaml_path)
load_config
end
|
#load_options(options) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/milc/base.rb', line 70
def load_options(options)
if options["c"]
load_from_yaml(options["c"])
else
show_help_and_exit1
end
end
|
#logger ⇒ Object
27
28
29
|
# File 'lib/milc/base.rb', line 27
def logger
Milc.logger
end
|
#run(args) ⇒ Object
92
93
94
95
96
|
# File 'lib/milc/base.rb', line 92
def run(args)
setup(args)
process
end
|
#setup(args) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/milc/base.rb', line 78
def setup(args)
args.extend(OptionParser::Arguable) unless args.is_a?(OptionParser::Arguable)
options = args.getopts(command_options)
show_help_and_exit1 unless args.empty?
Milc.dry_run = !!options["n"]
Milc.verbose = !!options["V"]
load_options(options)
end
|
#show_help_and_exit1 ⇒ Object
53
54
55
56
57
|
# File 'lib/milc/base.rb', line 53
def show_help_and_exit1
$stderr.puts help_message
exit 1
end
|