lono-params 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a5318c7d431c212dc1deb77a918fc3d3dcce2a5
4
- data.tar.gz: 3bcb90dcdd5a5cce47000e9ab38544cee6876f4c
3
+ metadata.gz: 79469aa41beee128511ce61e2a880608b6bbfcba
4
+ data.tar.gz: 55ea002171278b9da58f5486b511361f345e5ef0
5
5
  SHA512:
6
- metadata.gz: 307ac647c0ca743c1caed7c8c2d6d9b5dd934722e33b4cb1afb381e3938aaf39981f8f358dc7a51df31189615b90323ea141fce0d6794055d37d86ad231c6ad0
7
- data.tar.gz: ef16cc69a1064537ff9ee2c9cc5356d821e8c2eae5b4af92fc8279da7d1b349ed4b806d09f6d7b5456668a8f4430c7ebf1f6679b00aa054ebfd704eb5383ee7e
6
+ metadata.gz: b993abd2ac3196ef75c4b9eb8df48191d456a58acc23604492dfffda439057a1c1fc798ef0376fdb12573ca5466912da64507171030964f3e3ca42324d5eb804
7
+ data.tar.gz: 97e53b3377f59aa3c754ede75d8d579778a037b73711c7a6016c26c87132cd599ff29c01a2783cadd1c9f9ea0ad63ac88efee58b61574f5efe106cdba1c7603a
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
+
6
+ ## [0.0.4] Implement use_previous_value
7
+
8
+ - Implement use_previous_value: will create a hash with UsePreviousValue key.
9
+ - Allow trailing comment on the same line.
10
+
11
+ ## [0.0.1] Initial Release
12
+
13
+ - Initial release.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lono-params (0.0.1)
4
+ lono-params (0.0.4)
5
5
  colorize
6
6
  hashie
7
7
  plissken
data/README.md CHANGED
@@ -1,6 +1,30 @@
1
1
  # LonoParams
2
2
 
3
- Tool to generate a CloudFormation params json formatted file
3
+ Tool to generate a CloudFormation params json formatted file from a simplier env like file.
4
+
5
+ Given:
6
+
7
+ ```
8
+ Param1=1
9
+ Param2=1
10
+ ```
11
+
12
+ This is produced:
13
+
14
+ ```json
15
+ [
16
+ {
17
+ "ParameterKey": "Param1",
18
+ "ParameterValue": "1",
19
+ "UsePreviousValue": true
20
+ },
21
+ {
22
+ "ParameterKey": "Param2",
23
+ "ParameterValue": "1",
24
+ "UsePreviousValue": true
25
+ }
26
+ ]
27
+ ```
4
28
 
5
29
  ## Installation
6
30
 
@@ -21,10 +45,12 @@ Or install it yourself as:
21
45
  Create a directory under your project folder called `params`. Then given, a file with params in a simple list format:
22
46
 
23
47
  ```
24
- $ cat params/my-stack.txt
48
+ $ cat params/my-stack.txt
49
+ # comments are fine
25
50
  Param1=1
26
- Param2=1
27
- $
51
+ Param2=2 # comments can go after the line too
52
+ Param2=use_previous_value # treated specially
53
+ $
28
54
  ```
29
55
 
30
56
  Generate the CloudFormation json file that can be used with the `aws cloudformation create-stack` command.
@@ -32,7 +58,7 @@ Generate the CloudFormation json file that can be used with the `aws cloudformat
32
58
  ```
33
59
  $ lono-params generate my-stack
34
60
  Params file generated for my-stack at ./params/my-stack.json
35
- $
61
+ $
36
62
  ```
37
63
 
38
64
  This is what the `output/params/my-stack.json` file looks like:
@@ -41,12 +67,14 @@ This is what the `output/params/my-stack.json` file looks like:
41
67
  [
42
68
  {
43
69
  "ParameterKey": "Param1",
44
- "ParameterValue": "1",
45
- "UsePreviousValue": true
70
+ "ParameterValue": "1"
71
+ },
72
+ {
73
+ "ParameterKey": "Param2",
74
+ "ParameterValue": "2"
46
75
  },
47
76
  {
48
77
  "ParameterKey": "Param2",
49
- "ParameterValue": "1",
50
78
  "UsePreviousValue": true
51
79
  }
52
80
  ]
@@ -55,43 +83,9 @@ This is what the `output/params/my-stack.json` file looks like:
55
83
 
56
84
  ## More Help
57
85
 
58
-
59
- <pre>
86
+ ```
60
87
  $ bin/lono-params help
61
- Commands:
62
- lono-params generate NAME # generate parameter json file for NAME
63
- lono-params help [COMMAND] # Describe available commands or one specific command
64
-
65
- Options:
66
- [--verbose], [--no-verbose]
67
- [--noop], [--no-noop]
68
- [--project-root=PROJECT_ROOT] # project root to use
69
- # Default: .
70
-
71
- $ lono-params help generate
72
- /Users/tung/src/gitresolve/infra/lono/vendor/gems/lono-params/bin
73
- Usage:
74
- lono-params generate NAME
75
-
76
- Options:
77
- [--use-previous-value], [--no-use-previous-value]
78
- # Default: true
79
- [--verbose], [--no-verbose]
80
- [--noop], [--no-noop]
81
- [--project-root=PROJECT_ROOT] # project root to use
82
- # Default: .
83
-
84
- Description:
85
- Example:
86
-
87
- To generate a CloudFormation json file from params/my-stack.txt
88
-
89
- $ lono-params generate my-stack
90
-
91
- This will output a CloudFormation json file in output/params/my-stack.json
92
- $
93
- </pre>
94
-
88
+ ```
95
89
  ## Contributing
96
90
 
97
91
  1. Fork it
@@ -11,7 +11,6 @@ module LonoParams
11
11
  desc "generate NAME", "generate parameter json file for NAME"
12
12
  long_desc Help.generate
13
13
  option :path, desc: "Path of the source params txt file. Use this to override the params/NAME.txt convention"
14
- option :use_previous_value, type: :boolean, default: true
15
14
  def generate(name)
16
15
  Generator.new(name, options).generate
17
16
  end
@@ -13,7 +13,7 @@ module LonoParams
13
13
 
14
14
  def generate
15
15
  # useful option for lono-cfn
16
- return if @options[:allow_blank] && !File.exist?(@source_path)
16
+ return if @options[:allow_no_file] && !File.exist?(@source_path)
17
17
 
18
18
  if File.exist?(@source_path)
19
19
  contents = IO.read(@source_path)
@@ -30,7 +30,7 @@ module LonoParams
30
30
  # useful for when calling CloudFormation via the aws-sdk gem
31
31
  def params
32
32
  # useful option for lono-cfn
33
- return {} if @options[:allow_blank] && !File.exist?(@source_path)
33
+ return {} if @options[:allow_no_file] && !File.exist?(@source_path)
34
34
 
35
35
  contents = IO.read(@source_path)
36
36
  convert_to_cfn_format(contents, :underscore)
@@ -38,14 +38,12 @@ module LonoParams
38
38
 
39
39
  def parse_contents(contents)
40
40
  lines = contents.split("\n")
41
+ # remove comment at the end of the line
42
+ lines.map! { |l| l.sub(/#.*/,'').strip }
41
43
  # filter out commented lines
42
44
  lines = lines.reject { |l| l =~ /(^|\s)#/i }
43
45
  # filter out empty lines
44
46
  lines = lines.reject { |l| l.strip.empty? }
45
-
46
- # looked into trying to remove the commnet at the end of the line but it looks like the reliably way to do that by breaking the line into a syntax tree?
47
- # http://stackoverflow.com/questions/5865371/ruby-regex-for-finding-comments
48
- # http://stackoverflow.com/questions/7330171/how-to-match-code-comment-with-regex-in-ruby
49
47
  lines
50
48
  end
51
49
 
@@ -54,11 +52,17 @@ module LonoParams
54
52
  params = []
55
53
  lines.each do |line|
56
54
  key,value = line.strip.split("=").map {|x| x.strip}
57
- param = {
58
- "ParameterKey": key,
59
- "ParameterValue": value,
60
- "UsePreviousValue": @options[:use_previous_value]
61
- }
55
+ param = if value == "use_previous_value"
56
+ {
57
+ ParameterKey: key,
58
+ UsePreviousValue: true
59
+ }
60
+ else
61
+ {
62
+ ParameterKey: key,
63
+ ParameterValue: value
64
+ }
65
+ end
62
66
  param = param.to_snake_keys if casing == :underscore
63
67
  params << param
64
68
  end
@@ -1,3 +1,3 @@
1
1
  module LonoParams
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,2 +1,4 @@
1
+ # comments are fine
1
2
  Param1=1
2
- Param2=1
3
+ Param2=2 # comments can go after the line too
4
+ Param2=use_previous_value # treated specially
data/spec/lib/cli_spec.rb CHANGED
@@ -2,18 +2,38 @@ require 'spec_helper'
2
2
 
3
3
  # to run specs with what's remembered from vcr
4
4
  # $ rake
5
- #
5
+ #
6
6
  # to run specs with new fresh data from aws api calls
7
7
  # $ rake clean:vcr ; time rake
8
8
  describe LonoParams::CLI do
9
9
  before(:all) do
10
- @args = "--project-root spec/fixtures/my_project"
10
+ @project_root = "spec/fixtures/my_project"
11
+ @args = "--project-root #{@project_root}"
11
12
  end
12
13
 
13
14
  describe "lono-params" do
14
- it "should generate params" do
15
- out = execute("bin/lono-params generate my-stack #{@args}")
16
- expect(out).to include("Params file generated for my-stack")
15
+ context "generate" do
16
+ let(:output) { execute("bin/lono-params generate my-stack #{@args}") }
17
+ it "should generate output/params/my-stack.json params file" do
18
+ expect(output).to include("Params file generated for my-stack")
19
+ data = JSON.load(IO.read("#{@project_root}/output/params/my-stack.json"))
20
+ expect(data).to be_a(Array)
21
+ end
22
+
23
+ it "should treat use_previous_value as a special value" do
24
+ out = execute("bin/lono-params generate my-stack #{@args}")
25
+ expect(output).to include("Params file generated for my-stack")
26
+ data = JSON.load(IO.read("#{@project_root}/output/params/my-stack.json"))
27
+ param3 = data.last
28
+ expect(param3["UsePreviousValue"]).to be true
29
+ end
30
+
31
+ it "should remove comments" do
32
+ out = execute("bin/lono-params generate my-stack #{@args}")
33
+ expect(output).to include("Params file generated for my-stack")
34
+ data = JSON.load(IO.read("#{@project_root}/output/params/my-stack.json"))
35
+ expect(data.size).to eq 3
36
+ end
17
37
  end
18
38
  end
19
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lono-params
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2016-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -146,6 +146,7 @@ extra_rdoc_files: []
146
146
  files:
147
147
  - ".gitignore"
148
148
  - ".rspec"
149
+ - CHANGELOG.md
149
150
  - Gemfile
150
151
  - Gemfile.lock
151
152
  - Guardfile
@@ -190,4 +191,3 @@ test_files:
190
191
  - spec/fixtures/my_project/params/my-stack.txt
191
192
  - spec/lib/cli_spec.rb
192
193
  - spec/spec_helper.rb
193
- has_rdoc: