milc 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 134ae9236cb673f0c1182329f7da5b50f513dc85
4
- data.tar.gz: 83b991325dfc2683fe41d392b36e151f3f458c8e
3
+ metadata.gz: 5735bc7e72aa87ca2f8f91bae8fd2b6394454549
4
+ data.tar.gz: 93a8cfaf9d61bebbfcf4278706fb9512d4f2e4d2
5
5
  SHA512:
6
- metadata.gz: f3eed2dd80e4f4d4e26b1dba89c133ef207ac05330949480374463364b3fca1031e6d764d4e15684cc63fdb1a9e4951b537bf8f90aa7856754ea9ceef47367f8
7
- data.tar.gz: 17e6a97c1d1ec6b6a1702edb4912ff7cc3167ea202f9388651b6c2de7d6159f50d4413a1cfc1087f9cac620ecb1b3f6d0d365a4b303280800c4481e18661eee5
6
+ metadata.gz: 2cc1f200024d564b9b8e70d4a4798d023b2233195b182844593d6da0ae9aea84c96242242b4c7b90d09f49d61a7b2bbfa6b00d2567bd8e9682ffa5126d152865
7
+ data.tar.gz: d64616db530bc58b0bb1f2e33f9aff441f0258e70564e6a5e8cfb806a413eca33f1923a5dc2286ffa45e594c2530f6c155765404cd4a84dcc3a48542a3890cef
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
3
+ - 2.0.0
4
+ - 2.1.6
5
+ - 2.2.2
4
6
  before_install: gem install bundler --version '>= 1.8.0'
@@ -3,10 +3,11 @@ require "milc/version"
3
3
  require 'logger'
4
4
 
5
5
  module Milc
6
- autoload :Base, 'milc/base'
7
- autoload :Dsl , 'milc/dsl'
6
+ autoload :Base , 'milc/base'
7
+ autoload :Dsl , 'milc/dsl'
8
+ autoload :Gcloud , 'milc/gcloud'
8
9
 
9
- autoload :Gcloud, 'milc/gcloud'
10
+ autoload :Command, 'milc/command'
10
11
 
11
12
  class << self
12
13
  attr_accessor :dry_run
@@ -2,11 +2,8 @@
2
2
 
3
3
  require "milc"
4
4
 
5
- require 'json'
6
5
  require 'erb'
7
6
  require 'yaml'
8
- require 'optparse'
9
- require 'shellwords'
10
7
 
11
8
  require 'logger_pipe'
12
9
 
@@ -19,10 +16,6 @@ end
19
16
 
20
17
  module Milc
21
18
  module Base
22
- include Milc::Dsl::Gcloud
23
- include Milc::Dsl::Mgcloud
24
-
25
- include Milc::Dsl::Ansible
26
19
 
27
20
  def logger
28
21
  Milc.logger
@@ -34,28 +27,19 @@ module Milc
34
27
  block_given? ? yield(res) : res
35
28
  end
36
29
 
37
- def load_from_yaml(yaml_path)
38
- @config = YAML.load_file_with_erb(yaml_path)
39
- load_config
40
- end
41
-
42
- attr_reader :config
30
+ attr_accessor :config
43
31
  attr_reader :project
44
32
 
45
33
  def dry_run
46
34
  Milc.dry_run
47
35
  end
48
36
 
37
+ # overriden
49
38
  def load_config
50
39
  @project = config['PROJECT'] || ENV['PROJECT']
51
40
  end
52
41
 
53
- def show_help_and_exit1
54
- ## シェルスクリプトのUsage
55
- $stderr.puts help_message
56
- exit 1
57
- end
58
-
42
+ # overriden
59
43
  def help_message
60
44
  ## スクリプト名
61
45
  cmdname = File.basename($0) # $PROGRAM_NAME を推奨
@@ -63,36 +47,8 @@ module Milc
63
47
  "Usage: #{cmdname} -c CONF_FILE"
64
48
  end
65
49
 
66
- def command_options
67
- "nVc:" # n と V と c: は必須
68
- end
69
-
50
+ # overriden
70
51
  def load_options(options)
71
- if options["c"]
72
- load_from_yaml(options["c"])
73
- else
74
- show_help_and_exit1
75
- end
76
- end
77
-
78
- def setup(args)
79
- # ARGV.getopts については以下を参照
80
- # http://d.hatena.ne.jp/zariganitosh/20140819/ruby_optparser_true_power
81
- # http://docs.ruby-lang.org/ja/2.1.0/method/OptionParser=3a=3aArguable/i/getopts.html
82
- args.extend(OptionParser::Arguable) unless args.is_a?(OptionParser::Arguable)
83
- options = args.getopts(command_options)
84
- show_help_and_exit1 unless args.empty?
85
-
86
- Milc.dry_run = !!options["n"]
87
- Milc.verbose = !!options["V"]
88
-
89
- load_options(options)
90
- end
91
-
92
- def run(args)
93
- setup(args)
94
- process
95
- # exit 0
96
52
  end
97
53
 
98
54
  end
@@ -0,0 +1,57 @@
1
+ # coding: utf-8
2
+ require 'milc'
3
+
4
+ require 'optparse'
5
+
6
+ module Milc
7
+ class Command
8
+
9
+ attr_reader :logic
10
+ def initialize(logic)
11
+ @logic = logic
12
+ end
13
+
14
+ def run(args)
15
+ setup(args)
16
+ logic.process
17
+ # exit 0
18
+ end
19
+
20
+ def setup(args)
21
+ # ARGV.getopts については以下を参照
22
+ # http://d.hatena.ne.jp/zariganitosh/20140819/ruby_optparser_true_power
23
+ # http://docs.ruby-lang.org/ja/2.1.0/method/OptionParser=3a=3aArguable/i/getopts.html
24
+ args.extend(OptionParser::Arguable) unless args.is_a?(OptionParser::Arguable)
25
+ options = args.getopts(command_options)
26
+ show_help_and_exit1 unless args.empty?
27
+
28
+ Milc.dry_run = !!options["n"]
29
+ Milc.verbose = !!options["V"]
30
+
31
+ load_options(options)
32
+ end
33
+
34
+ # overriden
35
+ def command_options
36
+ "nVc:" # n と V と c: は必須
37
+ end
38
+
39
+ def show_help_and_exit1
40
+ ## シェルスクリプトのUsage
41
+ $stderr.puts logic.help_message
42
+ exit 1
43
+ end
44
+
45
+ def load_options(options)
46
+ if options["c"]
47
+ yaml_path = options["c"]
48
+ logic.config = YAML.load_file_with_erb(yaml_path)
49
+ logic.load_config
50
+ else
51
+ show_help_and_exit1
52
+ end
53
+ logic.load_options(options)
54
+ end
55
+
56
+ end
57
+ end
@@ -1,5 +1,7 @@
1
1
  require "milc/dsl"
2
2
 
3
+ require 'json'
4
+
3
5
  module Milc::Dsl
4
6
  module Gcloud
5
7
 
@@ -1,3 +1,3 @@
1
1
  module Milc
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-11 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logger_pipe
@@ -101,6 +101,7 @@ files:
101
101
  - exe/milc
102
102
  - lib/milc.rb
103
103
  - lib/milc/base.rb
104
+ - lib/milc/command.rb
104
105
  - lib/milc/dsl.rb
105
106
  - lib/milc/dsl/ansible.rb
106
107
  - lib/milc/dsl/gcloud.rb