cloudit 0.0.1 → 0.0.2

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: da3e9206140352d3a918034ad9f8eeb5c581ff38
4
- data.tar.gz: bd4c3f3c3f8464bc04e9699851e86ae8c4cff4c0
3
+ metadata.gz: 780b583f7f5295837b2a0e331c77cad8e6cd5a02
4
+ data.tar.gz: 96559c2b7b70bcb276a180ab5cd5f54b4674802d
5
5
  SHA512:
6
- metadata.gz: 2aad1cac49fa6bd722d10d91cb4a2664227fc7baa486c349f037ce624f12d0be7c08c3f2c1ffc9e2cd31fa8d772bcb02fc7a4b05c95dd6e744ecdf4a031e80d5
7
- data.tar.gz: 7a678a30a6f9c0a14fad26b853a2a15fec26abb87f531df595433d91e3069947b9b90fb793eb8d1d8695eee0e40dfd59820e05dc7c49908f4a7d890dfa36c331
6
+ metadata.gz: a32a506e54fce26769c79634ca4ed16130fc0e5f54f37e281a440d2c084ebbd157bef4818323783bb5a6dadeb5f8f736a132376b300af4307fb7f17f3e2dccef
7
+ data.tar.gz: 43e17214d3994c56b1581271f92e1ec97422d24e8424097f8929514aebdcf7b995a907796d2fe33a52e58c4dcf91fd2c472520afb89a7e7e2f9ff6b911863c73
data/Dockerfile CHANGED
@@ -3,4 +3,13 @@ FROM ruby:2.3.1
3
3
  # app dependencies
4
4
  RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
5
5
 
6
- RUN mkdir /usr/src/cloudit
6
+ ENV APP_HOME /usr/src/cloudit
7
+ RUN mkdir -p $APP_HOME
8
+ WORKDIR $APP_HOME
9
+
10
+ RUN mkdir -p $APP_HOME/lib/cloudit
11
+
12
+ ADD . $APP_HOME/
13
+ RUN bundle
14
+
15
+ RUN gem install byebug
data/bin/cloudit ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pathname"
4
+ bin_file = Pathname.new(__FILE__).realpath
5
+
6
+ # add self to libpath
7
+ $:.unshift File.expand_path("../../lib", bin_file)
8
+
9
+ require "cloudit/cli"
10
+
11
+ Cloudit::CLI.start *ARGV
data/cloudit.gemspec CHANGED
@@ -15,10 +15,11 @@ Gem::Specification.new do |spec|
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.executables = "cloudit"
20
19
  spec.require_paths = ["lib"]
21
20
 
21
+ spec.add_dependency "slop"
22
+
22
23
  spec.add_development_dependency "bundler", "~> 1.12"
23
24
  spec.add_development_dependency "rake", "~> 10.0"
24
25
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -0,0 +1,20 @@
1
+ require 'cloudit/command'
2
+
3
+ module Cloudit
4
+ class CLI
5
+
6
+ def self.start(*args)
7
+ $stdin.sync = true if $stdin.isatty
8
+ $stdout.sync = true if $stdout.isatty
9
+
10
+ if args[0] && !args[0].include?('-')
11
+ command = args.shift.strip rescue nil
12
+ else
13
+ nil
14
+ end
15
+
16
+ Cloudit::Command.load
17
+ Cloudit::Command.run(command, args)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,44 @@
1
+ require 'slop'
2
+ require 'byebug'
3
+
4
+ class Cloudit::Command::Base
5
+ class << self
6
+ attr_accessor :parser, :slop_opts
7
+ end
8
+
9
+ VALID_METHODS = []
10
+
11
+ def initialize(args=[])
12
+ @method = if args[0].is_a?(String) && args[0].include?('-')
13
+ nil
14
+ else
15
+ args.shift.strip rescue nil
16
+ end
17
+ @opts = parser.parse(args)
18
+ end
19
+
20
+ def execute
21
+ puts @method
22
+
23
+ if @method.nil?
24
+ index
25
+ elsif self.class::VALID_METHODS.include?(@method)
26
+ self.send(@method)
27
+ else
28
+ invalid_method
29
+ end
30
+ end
31
+
32
+ def help
33
+ $stdout.puts slop_opts
34
+ end
35
+
36
+ def parser
37
+ self.class.parser
38
+ end
39
+
40
+ def slop_opts
41
+ self.class.slop_opts
42
+ end
43
+
44
+ end
@@ -0,0 +1,67 @@
1
+ require 'cloudit/command/base'
2
+
3
+ require 'yaml'
4
+ require 'json'
5
+
6
+ class Cloudit::Command::Generate < Cloudit::Command::Base
7
+ VALID_METHODS = ['help']
8
+ SECTIONS = ['Metadata', 'Parameters', 'Mappings', 'Conditions', 'Resources', 'Outputs']
9
+
10
+ def index
11
+ if @opts.help?
12
+ $stdout.puts slop_opts
13
+ else
14
+ generate_json
15
+ end
16
+ end
17
+
18
+ def invalid_method
19
+ # TODO write method
20
+ help
21
+ end
22
+
23
+ private
24
+
25
+ def generate_json
26
+ hash = {}
27
+ hash_sections = {}
28
+
29
+ for file in Dir.glob(Dir['**/*.cfn.yml']) do
30
+ yml = YAML::load_file(file)
31
+ if yml.is_a?(Hash)
32
+ hash.merge! YAML::load_file(file)
33
+ end
34
+ end
35
+
36
+ for section in SECTIONS do
37
+ section_file = section.downcase
38
+ hash_sections[section] = {}
39
+
40
+ for file in Dir.glob(Dir["**/*.#{section_file}.yml"]) do
41
+ yml = YAML::load_file(file)
42
+
43
+ if yml.is_a?(Hash)
44
+ hash_sections[section].merge! yml
45
+ end
46
+ end
47
+ end
48
+
49
+ hash.merge! hash_sections
50
+
51
+ $stdout.puts hash.to_json
52
+ end
53
+
54
+ def self.setup_options
55
+ opts = Slop::Options.new
56
+ opts.banner = 'Usage: cloudit generate [options]'
57
+ opts.separator ''
58
+ opts.separator 'Generate options:'
59
+ opts.string '-o', '--output', 'a filename', default: 'out.json'
60
+ opts.bool '-h', '--help', 'print options', default: false
61
+
62
+ self.slop_opts = opts
63
+ self.parser = Slop::Parser.new(opts)
64
+ end
65
+
66
+ setup_options
67
+ end
@@ -0,0 +1,50 @@
1
+ require 'cloudit/version'
2
+ require 'cloudit/command/base'
3
+
4
+ require 'byebug'
5
+
6
+ class Cloudit::Command::Index < Cloudit::Command::Base
7
+ class << self
8
+ attr_accessor :usage
9
+ end
10
+
11
+ def usage
12
+ self.class.usage
13
+ end
14
+
15
+ def index
16
+ if @opts.version?
17
+ str = "Cloudit version #{Cloudit::VERSION}."
18
+ elsif @opts.help?
19
+ str = usage
20
+ else
21
+ str = usage
22
+ end
23
+ $stdout.puts str
24
+ end
25
+
26
+ private
27
+
28
+ def self.build_usage
29
+ str = slop_opts.to_s
30
+ Cloudit::Command.commands.each do |command|
31
+ str += command
32
+ end
33
+ self.usage = str
34
+ end
35
+
36
+ def self.setup_options
37
+ opts = Slop::Options.new
38
+ opts.banner = 'Usage: cloudit [OPTIONS] COMMAND [ARGS...]'
39
+ opts.separator ''
40
+ opts.separator 'Options:'
41
+ opts.bool '-v', '--version', 'print version', default: false
42
+ opts.bool '-h', '--help', 'print usage', default: false
43
+
44
+ self.slop_opts = opts
45
+ self.parser = Slop::Parser.new(opts)
46
+ end
47
+
48
+ setup_options
49
+ build_usage
50
+ end
@@ -0,0 +1,37 @@
1
+ module Cloudit
2
+ module Command
3
+ class << self
4
+ attr_accessor :commands
5
+ end
6
+
7
+ @commands = []
8
+
9
+ def self.load
10
+ Dir[File.join(File.dirname(__FILE__), "command", "*.rb")].each do |file|
11
+ self.commands << file.split('/')[-1].chomp('.rb')
12
+ require file
13
+ end
14
+ end
15
+
16
+ def self.run(command, args)
17
+ begin
18
+ if command.nil?
19
+ command = 'index'
20
+ elsif command == 'index'
21
+ raise NameError if command == 'index'
22
+ end
23
+ klass = "Cloudit::Command::#{command.capitalize}"
24
+ instance = Object.const_get(klass).new(args)
25
+ rescue NameError
26
+ $stdout.puts "cloudit: '#{command}' is not a cloudit command.\nSee 'cloudit --help' for usage."
27
+ exit(1)
28
+ end
29
+ instance.execute
30
+ end
31
+
32
+ def commands
33
+ self.class.commands
34
+ end
35
+
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module Cloudit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/cloudit.rb CHANGED
@@ -1,2 +1 @@
1
1
  require "cloudit/version"
2
- require "cloudit/core"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Chai
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-29 00:00:00.000000000 Z
11
+ date: 2016-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -68,13 +82,15 @@ files:
68
82
  - LICENSE.txt
69
83
  - README.md
70
84
  - Rakefile
71
- - bin/console
72
- - bin/setup
85
+ - bin/cloudit
73
86
  - cloudit.gemspec
74
87
  - docker-compose.yml
75
- - exe/cloudit
76
88
  - lib/cloudit.rb
77
- - lib/cloudit/core.rb
89
+ - lib/cloudit/cli.rb
90
+ - lib/cloudit/command.rb
91
+ - lib/cloudit/command/base.rb
92
+ - lib/cloudit/command/generate.rb
93
+ - lib/cloudit/command/index.rb
78
94
  - lib/cloudit/version.rb
79
95
  homepage: https://github.com/zach-chai/cloudit
80
96
  licenses:
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "cloudit"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/exe/cloudit DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "cloudit"
data/lib/cloudit/core.rb DELETED
@@ -1,37 +0,0 @@
1
- require 'yaml'
2
- require 'json'
3
-
4
- module Cloudit
5
- class Core
6
- SECTIONS = ['Metadata', 'Parameters', 'Mappings', 'Conditions', 'Resources', 'Outputs']
7
-
8
- def generate
9
- hash = {}
10
- hash_sections = {}
11
-
12
- for file in Dir.glob(Dir["**/*.cfn.yml"]) do
13
- yml = YAML::load_file(file)
14
- if yml.is_a?(Hash)
15
- hash.merge! YAML::load_file(file)
16
- end
17
- end
18
-
19
- for section in SECTIONS do
20
- section_file = section.downcase
21
- hash_sections[section] = {}
22
-
23
- for file in Dir.glob(Dir["**/*.#{section_file}.yml"]) do
24
- yml = YAML::load_file(file)
25
-
26
- if yml.is_a?(Hash)
27
- hash_sections[section].merge! yml
28
- end
29
- end
30
- end
31
-
32
- hash.merge! hash_sections
33
-
34
- puts hash.to_json
35
- end
36
- end
37
- end