Module: Milc::Base
- Includes:
- Dsl::Ansible, Dsl::Gcloud, Dsl::Mgcloud
- Defined in:
- lib/milc/base.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
- #command_options ⇒ Object
- #dry_run ⇒ Object
- #execute(cmd) ⇒ Object
- #help_message ⇒ Object
- #load_config ⇒ Object
- #load_from_yaml(yaml_path) ⇒ Object
- #load_options(options) ⇒ Object
- #logger ⇒ Object
- #run(args) ⇒ Object
- #setup(args) ⇒ Object
- #show_help_and_exit1 ⇒ Object
Methods included from Dsl::Ansible
Methods included from Dsl::Mgcloud
Methods included from Dsl::Gcloud
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
41 42 43 |
# File 'lib/milc/base.rb', line 41 def config @config end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
42 43 44 |
# File 'lib/milc/base.rb', line 42 def project @project end |
Instance Method Details
#command_options ⇒ Object
65 66 67 |
# File 'lib/milc/base.rb', line 65 def "nVc:" # n と V と c: は必須 end |
#dry_run ⇒ Object
44 45 46 |
# File 'lib/milc/base.rb', line 44 def dry_run Milc.dry_run end |
#execute(cmd) ⇒ Object
31 32 33 34 |
# File 'lib/milc/base.rb', line 31 def execute(cmd) res = LoggerPipe.run(logger, cmd, dry_run: Milc.dry_run) block_given? ? yield(res) : res end |
#help_message ⇒ Object
58 59 60 61 62 63 |
# File 'lib/milc/base.rb', line 58 def ## スクリプト名 cmdname = File.basename($0) # $PROGRAM_NAME を推奨 ## シェルスクリプトのUsage "Usage: #{cmdname} -c CONF_FILE" end |
#load_config ⇒ Object
48 49 50 |
# File 'lib/milc/base.rb', line 48 def load_config @project = config['PROJECT'] || ENV['PROJECT'] end |
#load_from_yaml(yaml_path) ⇒ Object
36 37 38 39 |
# File 'lib/milc/base.rb', line 36 def load_from_yaml(yaml_path) @config = YAML.load_file_with_erb(yaml_path) load_config end |
#load_options(options) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/milc/base.rb', line 69 def () if ["c"] load_from_yaml(["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
91 92 93 94 95 |
# File 'lib/milc/base.rb', line 91 def run(args) setup(args) process # exit 0 end |
#setup(args) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/milc/base.rb', line 77 def setup(args) # ARGV.getopts については以下を参照 # http://d.hatena.ne.jp/zariganitosh/20140819/ruby_optparser_true_power # http://docs.ruby-lang.org/ja/2.1.0/method/OptionParser=3a=3aArguable/i/getopts.html args.extend(OptionParser::Arguable) unless args.is_a?(OptionParser::Arguable) = args.getopts() show_help_and_exit1 unless args.empty? Milc.dry_run = !!["n"] Milc.verbose = !!["V"] () end |
#show_help_and_exit1 ⇒ Object
52 53 54 55 56 |
# File 'lib/milc/base.rb', line 52 def show_help_and_exit1 ## シェルスクリプトのUsage $stderr.puts exit 1 end |