cloudit 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cloudit.gemspec +2 -0
- data/lib/cloudit/command/base.rb +5 -0
- data/lib/cloudit/command/generate.rb +36 -8
- data/lib/cloudit/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c668f56969001a73c0ca0df7d5c5d9336b8d3bb2
|
4
|
+
data.tar.gz: b882f0ad4625a9eff7de0b394ad688bf15ca252b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 316d6063727d2cdc87612764a3a6a995f58d7b14592fe9be4a942b4acd78eb9c61cc0321ecdaed3d7881924a4c696a539182fc7996bb3970321031cd46ab1039
|
7
|
+
data.tar.gz: 827c215133829429b81ab3cd49f53e9ef005c3d4f6b627830a8c196dd09b07dd6e7d56b5cf3bf90a0ed47287dfd094038ab17a971e488ad0e82a8d32f3a2fbd8
|
data/cloudit.gemspec
CHANGED
data/lib/cloudit/command/base.rb
CHANGED
@@ -7,6 +7,7 @@ class Cloudit::Command::Base
|
|
7
7
|
end
|
8
8
|
|
9
9
|
VALID_METHODS = []
|
10
|
+
OPTION_NAME_OFFSET = 6
|
10
11
|
|
11
12
|
def initialize(args=[])
|
12
13
|
@method = if args[0].is_a?(String) && args[0].include?('-')
|
@@ -29,6 +30,10 @@ class Cloudit::Command::Base
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
33
|
+
def invalid_method
|
34
|
+
$stdout.puts "cloudit: '#{@method}' is not a cloudit command\nSee 'cloudit --help'"
|
35
|
+
end
|
36
|
+
|
32
37
|
def help
|
33
38
|
$stdout.puts slop_opts
|
34
39
|
end
|
@@ -6,6 +6,9 @@ require 'json'
|
|
6
6
|
class Cloudit::Command::Generate < Cloudit::Command::Base
|
7
7
|
VALID_METHODS = ['help']
|
8
8
|
SECTIONS = ['Metadata', 'Parameters', 'Mappings', 'Conditions', 'Resources', 'Outputs']
|
9
|
+
DEFAULT_OUT_FILE = 'out.json'
|
10
|
+
DEFAULT_MAIN_CFN_EXTENSION = 'cfn.yml'
|
11
|
+
DEFAULT_DIRECTORY = './'
|
9
12
|
|
10
13
|
def index
|
11
14
|
if @opts.help?
|
@@ -15,18 +18,33 @@ class Cloudit::Command::Generate < Cloudit::Command::Base
|
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
|
-
def invalid_method
|
19
|
-
# TODO write method
|
20
|
-
help
|
21
|
-
end
|
22
|
-
|
23
21
|
private
|
24
22
|
|
25
23
|
def generate_json
|
26
24
|
hash = {}
|
27
25
|
hash_sections = {}
|
26
|
+
out = @opts[:output]
|
27
|
+
dir = normalize_directory @opts[:directory]
|
28
|
+
|
29
|
+
if File.exist? out
|
30
|
+
if out.eql? DEFAULT_OUT_FILE
|
31
|
+
i = 1
|
32
|
+
while File.exist? out
|
33
|
+
i += 1
|
34
|
+
out = "out#{i}.json"
|
35
|
+
end
|
36
|
+
else
|
37
|
+
$stdout.puts "cloudit: output file '#{out}' already exists"
|
38
|
+
return
|
39
|
+
end
|
40
|
+
end
|
28
41
|
|
29
|
-
|
42
|
+
unless File.directory? dir
|
43
|
+
$stdout.puts "cloudit: '#{dir}' must be a directory"
|
44
|
+
return
|
45
|
+
end
|
46
|
+
|
47
|
+
for file in Dir.glob(Dir["#{dir}**/*.#{DEFAULT_MAIN_CFN_EXTENSION}"]) do
|
30
48
|
yml = YAML::load_file(file)
|
31
49
|
if yml.is_a?(Hash)
|
32
50
|
hash.merge! YAML::load_file(file)
|
@@ -37,7 +55,7 @@ class Cloudit::Command::Generate < Cloudit::Command::Base
|
|
37
55
|
section_file = section.downcase
|
38
56
|
hash_sections[section] = {}
|
39
57
|
|
40
|
-
for file in Dir.glob(Dir["**/*.#{section_file}.yml"]) do
|
58
|
+
for file in Dir.glob(Dir["#{dir}**/*.#{section_file}.yml"]) do
|
41
59
|
yml = YAML::load_file(file)
|
42
60
|
|
43
61
|
if yml.is_a?(Hash)
|
@@ -49,6 +67,15 @@ class Cloudit::Command::Generate < Cloudit::Command::Base
|
|
49
67
|
hash.merge! hash_sections
|
50
68
|
|
51
69
|
$stdout.puts hash.to_json
|
70
|
+
File.new(out, 'w').write "#{hash.to_json}\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
def normalize_directory(dir)
|
74
|
+
if dir.end_with? '/'
|
75
|
+
dir
|
76
|
+
else
|
77
|
+
dir + '/'
|
78
|
+
end
|
52
79
|
end
|
53
80
|
|
54
81
|
def self.setup_options
|
@@ -56,8 +83,9 @@ class Cloudit::Command::Generate < Cloudit::Command::Base
|
|
56
83
|
opts.banner = 'Usage: cloudit generate [options]'
|
57
84
|
opts.separator ''
|
58
85
|
opts.separator 'Generate options:'
|
59
|
-
opts.string '-o', '--output', '
|
86
|
+
opts.string '-o', '--output', 'output filename', default: DEFAULT_OUT_FILE
|
60
87
|
opts.bool '-h', '--help', 'print options', default: false
|
88
|
+
opts.string '-d', '--directory', 'root directory to generate', default: DEFAULT_DIRECTORY
|
61
89
|
|
62
90
|
self.slop_opts = opts
|
63
91
|
self.parser = Slop::Parser.new(opts)
|
data/lib/cloudit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Chai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05
|
11
|
+
date: 2016-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|
@@ -104,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
104
|
requirements:
|
105
105
|
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version: '0'
|
107
|
+
version: '2.0'
|
108
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
110
|
- - ">="
|