lono 4.0.6 → 4.1.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
  SHA256:
3
- metadata.gz: 6f63015f7f02dd2c10b5a5fdb6e1ee6b39dbba2a76e72fd2dbffa60fa2a8361e
4
- data.tar.gz: 72f5b4c8b8adfb43a52e9b10bc3786a103c8494bf05a2c16302cb3211c03a728
3
+ metadata.gz: 14ca2afc46780d2abc5bb0ecabaf53a685befb89abe63263fa02d847201582f4
4
+ data.tar.gz: b3ccb40f3ecc4902b769651c67ef1a76dfb330c0d547c3da686e2913857b048a
5
5
  SHA512:
6
- metadata.gz: 75d69ff2904e89e0983876bd5210c29a163a91d92262555910b8db803a4a9530a97487abf97841516f62319c2b175991dfe856f6a9218267442392796d0bf1ce
7
- data.tar.gz: 3897781b6b686829406821477af5e5bc0ef8e48fa16ec73337020ab96f5ea534f21c1a88c25487847352ec396301f64a61bc3f28f6b5b192ba806886f10ebbac
6
+ metadata.gz: 63bcc9ff8a025fba3666fb8bcd73fb1a7ffa5e9382dcdf2d407f4c7ea678fb63302887a3bddc8f527c13846100af26d91361f6a7f9bfc2583d4345635ab698de
7
+ data.tar.gz: ac98507f3f1a706602662f47af7055b6b983c6c373d8c78f13706dab323fbf8a33d35b16d87234de9674ca7e2c5464d2dcfe1cbd475f6d1ba19b6539ba81a7a1
@@ -3,6 +3,13 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [4.1.0]
7
+ - Merge pull request #36 from tongueroo/cli_markdown
8
+ - fix current_region helper in variables, add s3_region setting
9
+ - settings: fix edge cases, nil base, file is empty
10
+ - simplify how to set s3 endpoint override so region doesnt have to also be set
11
+ - use subshell for extract_scripts
12
+
6
13
  ## [4.0.6]
7
14
  - Update cli docs: generate, import, new, upload
8
15
  - fix thor description override when command not found
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem "codeclimate-test-reporter", group: :test, require: nil
7
+
data/Rakefile CHANGED
@@ -6,7 +6,8 @@ task :default => :spec
6
6
  RSpec::Core::RakeTask.new
7
7
 
8
8
  require_relative "lib/lono"
9
+ require "cli_markdown"
9
10
  desc "Generates cli reference docs as markdown"
10
11
  task :docs do
11
- Lono::Markdown::Creator.create_all(Lono::CLI)
12
+ CliMarkdown::Creator.create_all(cli_class: Lono::CLI, cli_name: "lono")
12
13
  end
@@ -33,7 +33,6 @@ module Lono
33
33
  autoload :Upgrade4, 'lono/upgrade4'
34
34
  autoload :Script, 'lono/script'
35
35
  autoload :UserData, 'lono/user_data'
36
- autoload :Markdown, 'lono/markdown'
37
36
 
38
37
  extend Core
39
38
  end
@@ -54,14 +54,28 @@ module Lono
54
54
 
55
55
  def alter_command_description(command)
56
56
  return unless command
57
+
58
+ # Add description to beginning of long_description
57
59
  long_desc = if command.long_description
58
60
  "#{command.description}\n\n#{command.long_description}"
59
61
  else
60
62
  command.description
61
63
  end
64
+
65
+ # add reference url to end of the long_description
66
+ unless website.empty?
67
+ full_command = [command.ancestor_name, command.name].compact.join('-')
68
+ url = "#{website}/reference/lono-#{full_command}"
69
+ long_desc += "\n\nAlso available at: #{url}"
70
+ end
71
+
62
72
  command.long_description = long_desc
63
73
  end
64
74
  private :alter_command_description
75
+
76
+ def website
77
+ "http://lono.cloud"
78
+ end
65
79
  end
66
80
  end
67
81
  end
@@ -34,7 +34,7 @@ class Lono::Importer
34
34
 
35
35
  def show_params_file
36
36
  path = "config/params/base/#{template_name}.txt"
37
- puts "Here are contents of the params #{path} file:"
37
+ puts "Here are contents of the params #{path.colorize(:green)} file:"
38
38
  puts IO.read("#{Lono.root}/#{path}")
39
39
  end
40
40
 
@@ -3,7 +3,6 @@ class Lono::Inspector::Summary < Lono::Inspector::Base
3
3
  puts "=> CloudFormation Template Summary:".colorize(:green)
4
4
  return if @options[:noop]
5
5
 
6
- puts "Parameters:"
7
6
  print_parameters_summary
8
7
 
9
8
  puts "Resources:"
@@ -12,10 +11,10 @@ class Lono::Inspector::Summary < Lono::Inspector::Base
12
11
 
13
12
  def print_parameters_summary
14
13
  if parameters.empty?
15
- puts " There are no parameters"
14
+ puts "There are no parameters in this template."
16
15
  else
17
- print_parameters("Required", required_parameters)
18
- print_parameters("Optional", optional_parameters)
16
+ print_parameters("Required Parameters", required_parameters)
17
+ print_parameters("Optional Parameters", optional_parameters)
19
18
  end
20
19
  end
21
20
 
@@ -58,7 +58,7 @@ module Lono
58
58
  return Hash.new({}) unless File.exist?(path)
59
59
 
60
60
  content = RenderMePretty.result(path)
61
- data = YAML.load(content)
61
+ data = YAML.load(content) || {}
62
62
  # If key is is accidentally set to nil it screws up the merge_base later.
63
63
  # So ensure that all keys with nil value are set to {}
64
64
  data.each do |lono_env, _setting|
@@ -69,7 +69,7 @@ module Lono
69
69
 
70
70
  # automatically add base settings to the rest of the environments
71
71
  def merge_base(all_envs)
72
- base = all_envs["base"]
72
+ base = all_envs["base"] || {}
73
73
  all_envs.each do |lono_env, env_settings|
74
74
  all_envs[lono_env] = base.merge(env_settings) unless lono_env == "base"
75
75
  end
@@ -5,11 +5,16 @@ module Lono::Template::AwsService
5
5
  return @s3 if @s3
6
6
 
7
7
  options = {}
8
- # example: endpoint: 'https://s3.us-west-2.amazonaws.com'
9
- options[:endpoint] = ENV['S3_ENDPOINT'] if ENV['S3_ENDPOINT']
10
8
  # allow override of region for s3 client to avoid warning:
11
9
  # S3 client configured for "us-east-1" but the bucket "xxx" is in "us-west-2"; Please configure the proper region to avoid multiple unnecessary redirects and signing attempts
12
- options[:region] = ENV['S3_REGION'] if ENV['S3_REGION']
10
+ # Example: endpoint: 'https://s3.us-west-2.amazonaws.com'
11
+ settings = Lono::Setting.new.data
12
+ endpoint = settings["s3_endpoint"]
13
+ endpoint = ENV['S3_ENDPOINT'] if ENV['S3_ENDPOINT']
14
+ options[:endpoint] = endpoint if endpoint
15
+ if options[:endpoint]
16
+ options[:region] = options[:endpoint].split('.')[1]
17
+ end
13
18
  @s3 = Aws::S3::Client.new(options)
14
19
  end
15
20
  end
@@ -1,3 +1,5 @@
1
+ require "aws-sdk-core"
2
+
1
3
  # This is included into Lono::Template::Context.
2
4
  # It has access to the original thor CLI options via @options.
3
5
  #
@@ -27,10 +29,12 @@ module Lono::Template::Helper
27
29
  # Downloads scripts from s3, extract them, and setup.
28
30
  mkdir -p #{to}
29
31
  aws s3 cp #{scripts_s3_path} #{to}/
30
- cd #{to}
31
- tar zxf #{to}/#{scripts_name}
32
- chmod -R a+x #{to}/scripts
33
- chown -R #{user}:#{user} #{to}/scripts
32
+ (
33
+ cd #{to}
34
+ tar zxf #{to}/#{scripts_name}
35
+ chmod -R a+x #{to}/scripts
36
+ chown -R #{user}:#{user} #{to}/scripts
37
+ )
34
38
  BASH_CODE
35
39
  end
36
40
 
@@ -1,3 +1,3 @@
1
1
  module Lono
2
- VERSION = "4.0.6"
2
+ VERSION = "4.1.0"
3
3
  end
@@ -37,6 +37,7 @@ Gem::Specification.new do |gem|
37
37
  # until https://github.com/futurechimp/plissken/pull/6 gets merged
38
38
 
39
39
  gem.add_development_dependency "byebug"
40
+ gem.add_development_dependency "cli_markdown"
40
41
  gem.add_development_dependency "guard-bundler"
41
42
  gem.add_development_dependency "guard-rspec"
42
43
  gem.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lono
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.6
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-26 00:00:00.000000000 Z
11
+ date: 2018-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -220,6 +220,20 @@ dependencies:
220
220
  - - ">="
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: cli_markdown
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
223
237
  - !ruby/object:Gem::Dependency
224
238
  name: guard-bundler
225
239
  requirement: !ruby/object:Gem::Requirement
@@ -347,11 +361,6 @@ files:
347
361
  - lib/lono/inspector/base.rb
348
362
  - lib/lono/inspector/graph.rb
349
363
  - lib/lono/inspector/summary.rb
350
- - lib/lono/markdown.rb
351
- - lib/lono/markdown/creator.rb
352
- - lib/lono/markdown/index.rb
353
- - lib/lono/markdown/page.rb
354
- - lib/lono/markdown/shell.rb
355
364
  - lib/lono/new.rb
356
365
  - lib/lono/new/helper.rb
357
366
  - lib/lono/new/message.rb
@@ -437,7 +446,6 @@ files:
437
446
  - spec/lib/lono/cli_spec.rb
438
447
  - spec/lib/lono/completion_spec.rb
439
448
  - spec/lib/lono/inspect_spec.rb
440
- - spec/lib/lono/markdown_spec.rb
441
449
  - spec/lib/lono/param/generator_spec.rb
442
450
  - spec/lib/lono/param_spec.rb
443
451
  - spec/lib/lono/setting_spec.rb
@@ -511,7 +519,6 @@ test_files:
511
519
  - spec/lib/lono/cli_spec.rb
512
520
  - spec/lib/lono/completion_spec.rb
513
521
  - spec/lib/lono/inspect_spec.rb
514
- - spec/lib/lono/markdown_spec.rb
515
522
  - spec/lib/lono/param/generator_spec.rb
516
523
  - spec/lib/lono/param_spec.rb
517
524
  - spec/lib/lono/setting_spec.rb
@@ -1,8 +0,0 @@
1
- require 'thor'
2
-
3
- module Lono::Markdown
4
- autoload :Creator, 'lono/markdown/creator'
5
- autoload :Index, 'lono/markdown/index'
6
- autoload :Page, 'lono/markdown/page'
7
- autoload :Shell, 'lono/markdown/shell'
8
- end
@@ -1,65 +0,0 @@
1
- require "active_support/core_ext/object"
2
-
3
- module Lono::Markdown
4
- class Creator
5
- cattr_accessor :mute
6
-
7
- def self.create_all(command_class, parent_command_name=nil)
8
- clean unless parent_command_name
9
- new(command_class, parent_command_name).create_all
10
- end
11
-
12
- def self.clean
13
- FileUtils.rm_rf("docs/_reference")
14
- FileUtils.rm_f("docs/reference.md")
15
- end
16
-
17
- # command_class is top-level CLI class.
18
- def initialize(command_class, parent_command_name)
19
- @command_class = command_class
20
- @parent_command_name = parent_command_name
21
- end
22
-
23
- def create_all
24
- create_index unless @parent_command_name
25
-
26
- @command_class.commands.keys.each do |command_name|
27
- page = Page.new(@command_class, command_name, @parent_command_name)
28
- create_page(page)
29
-
30
- if subcommand?(command_name)
31
- subcommand_class = subcommand_class(command_name)
32
- parent_command_name = command_name
33
-
34
- say "Creating subcommands pages for #{parent_command_name}..."
35
- Creator.create_all(subcommand_class, parent_command_name)
36
- end
37
- end
38
- end
39
-
40
- def create_page(page)
41
- say "Creating #{page.path}..."
42
- FileUtils.mkdir_p(File.dirname(page.path))
43
- IO.write(page.path, page.doc)
44
- end
45
-
46
- def create_index
47
- page = Index.new(@command_class)
48
- FileUtils.mkdir_p(File.dirname(page.path))
49
- say "Creating #{page.path}"
50
- IO.write(page.path, page.doc)
51
- end
52
-
53
- def subcommand?(command_name)
54
- @command_class.subcommands.include?(command_name)
55
- end
56
-
57
- def subcommand_class(command_name)
58
- @command_class.subcommand_classes[command_name]
59
- end
60
-
61
- def say(text)
62
- puts text unless self.class.mute
63
- end
64
- end
65
- end
@@ -1,36 +0,0 @@
1
- module Lono::Markdown
2
- class Index
3
- def initialize(command_class)
4
- @command_class = command_class
5
- end
6
-
7
- def path
8
- "docs/reference.md"
9
- end
10
-
11
- def command_list
12
- @command_class.commands.keys.sort.map.each do |command_name|
13
- page = Page.new(@command_class, command_name)
14
- link = page.path.sub("docs/", "")
15
- # Example: [lono cfn]({% link _reference/lono-cfn.md %})
16
- "* [lono #{command_name}]({% link #{link} %})"
17
- end.join("\n")
18
- end
19
-
20
- def summary
21
- <<-EOL
22
- Lono is a CloudFormation framework tool that helps you manage your templates. Lono handles the entire CloudFormation lifecycle. It starts with helping you develop your templates and helps you all the way to the infrastructure provisioning step.
23
- EOL
24
- end
25
-
26
- def doc
27
- <<-EOL
28
- ---
29
- title: CLI Reference
30
- ---
31
- #{summary}
32
- #{command_list}
33
- EOL
34
- end
35
- end
36
- end
@@ -1,169 +0,0 @@
1
- module Lono::Markdown
2
- class Page
3
- def initialize(command_class, command_name, parent_command_name=nil)
4
- @command_class = command_class
5
- @command_name = command_name
6
- @parent_command_name = parent_command_name
7
- @command = @command_class.commands[@command_name]
8
- end
9
-
10
- def usage
11
- banner = @command_class.send(:banner, @command) # banner is protected method
12
- invoking_command = File.basename($0) # could be rspec, etc
13
- banner.sub(invoking_command, cli_name)
14
- end
15
-
16
- def description
17
- @command.description
18
- end
19
-
20
- def options
21
- shell = Shell.new
22
- @command_class.send(:class_options_help, shell, nil => @command.options.values)
23
- text = shell.stdout.string
24
- return "" if text.empty? # there are no options
25
-
26
- lines = text.split("\n")[1..-1] # remove first line wihth "Options: "
27
- lines.map! do |line|
28
- # remove 2 leading spaces
29
- line.sub(/^ /, '')
30
- end
31
- lines.join("\n")
32
- end
33
-
34
- # Use command's long description as many description
35
- def long_description
36
- text = @command.long_description
37
- return "" if text.nil? # empty description
38
-
39
- lines = text.split("\n")
40
- lines.map do |line|
41
- # In the CLI help, we use 2 spaces to designate commands
42
- # In Markdown we need 4 spaces.
43
- line.sub(/^ \b/, ' ')
44
- end.join("\n")
45
- end
46
-
47
- def cli_name
48
- "lono"
49
- end
50
-
51
- def path
52
- full_name = if @parent_command_name
53
- "#{cli_name}-#{@parent_command_name}-#{@command_name}"
54
- else
55
- "#{cli_name}-#{@command_name}"
56
- end
57
- "docs/_reference/#{full_name}.md"
58
- end
59
-
60
- def subcommand?
61
- @command_class.subcommands.include?(@command_name)
62
- end
63
-
64
- def subcommand_class
65
- @command_class.subcommand_classes[@command_name]
66
- end
67
-
68
- # Note:
69
- # printable_commands are in the form:
70
- # [
71
- # [command_form,command_comment],
72
- # [command_form,command_comment],
73
- # ]
74
- #
75
- # It is useful to grab the command form printable_commands as it shows
76
- # the proper form.
77
- def subcommand_list
78
- return '' unless subcommand?
79
-
80
- invoking_command = File.basename($0) # could be rspec, etc
81
- command_list = subcommand_class.printable_commands
82
- .sort_by { |a| a[0] }
83
- .map { |a| a[0].sub!(invoking_command, cli_name); a } # replace with proper comand
84
- .reject { |a| a[0].include?("help [COMMAND]") } # filter out help
85
-
86
- # dress up with markdown
87
- text = command_list.map do |a|
88
- command, comment = a[0], a[1].sub(/^# /,'')
89
- subcommand_name = command.split(' ')[2]
90
- full_command_path = "#{cli_name}-#{@command_name}-#{subcommand_name}"
91
- full_command_name = "#{cli_name} #{@command_name} #{subcommand_name}"
92
- link = "_reference/#{full_command_path}.md"
93
-
94
- # "* [#{command}]({% link #{link} %})"
95
- # Example: [lono cfn delete STACK]({% link _reference/lono-cfn-delete.md %})
96
- "* [#{full_command_name}]({% link #{link} %}) - #{comment}"
97
- end.join("\n")
98
-
99
- <<-EOL
100
- ## Subcommands
101
-
102
- #{text}
103
- EOL
104
- end
105
-
106
- def doc
107
- <<-EOL
108
- #{front_matter}
109
- #{usage_markdown}
110
- #{long_desc_markdown}
111
- #{subcommand_list}
112
- #{options_markdown}
113
- EOL
114
- end
115
-
116
- def front_matter
117
- command = [cli_name, @parent_command_name, @command_name].compact.join(' ')
118
- <<-EOL
119
- ---
120
- title: #{command}
121
- reference: true
122
- ---
123
- EOL
124
- end
125
-
126
- def usage_markdown
127
- <<-EOL
128
- ## Usage
129
-
130
- #{usage}
131
- EOL
132
- end
133
-
134
- def desc_markdown
135
- <<-EOL
136
- ## Description
137
-
138
- #{description}
139
- EOL
140
- end
141
-
142
- # If the Thor long_description is empty then use the description.
143
- def long_desc_markdown
144
- return desc_markdown if long_description.empty?
145
-
146
- <<-EOL
147
- ## Description
148
-
149
- #{description}
150
-
151
- #{long_description}
152
- EOL
153
- end
154
-
155
- # handles blank options
156
- def options_markdown
157
- return '' if options.empty?
158
-
159
- <<-EOL
160
- ## Options
161
-
162
- ```
163
- #{options}
164
- ```
165
- EOL
166
- end
167
-
168
- end
169
- end
@@ -1,11 +0,0 @@
1
- require 'thor'
2
-
3
- module Lono::Markdown
4
- # Override stdout as an @io object so we can grab the text written normally
5
- # outputted to the shell.
6
- class Shell < Thor::Shell::Basic
7
- def stdout
8
- @io ||= StringIO.new
9
- end
10
- end
11
- end
@@ -1,87 +0,0 @@
1
- describe Lono::Markdown::Page do
2
- let(:page) { Lono::Markdown::Page.new(cli_class, command, parent_command_name) }
3
- let(:cli_class) { Lono::CLI }
4
- let(:parent_command_name) { nil }
5
-
6
- context "MarkdownMaker.create_all" do
7
- it "docs command" do
8
- out = execute("rake docs")
9
- expect(out).to include("Creating")
10
- end
11
-
12
- it "generates all docs pages" do
13
- Lono::Markdown::Creator.mute = true
14
- Lono::Markdown::Creator.create_all(cli_class)
15
- end
16
- end
17
-
18
- context "generate" do
19
- let(:command) { "generate" }
20
-
21
- it "#usage" do
22
- expect(page.usage).to eq "lono generate"
23
- end
24
-
25
- it "#desc_markdown" do
26
- expect(page.desc_markdown).to include "# Description"
27
- end
28
-
29
- it "#options_markdown" do
30
- expect(page.options_markdown).to include("--clean")
31
- # [--clean], [--no-clean] # remove all output files before generating
32
- # # Default: true
33
- # [--quiet], [--no-quiet] # silence the output
34
- end
35
-
36
- it "#doc" do
37
- expect(page.doc).to include("# Description")
38
- # puts page.doc # uncomment to see generated page for debugging
39
- end
40
- end
41
-
42
- # subcommand
43
- context "cfn" do
44
- let(:command) { "cfn" }
45
-
46
- it "#usage" do
47
- expect(page.usage).to eq "lono cfn SUBCOMMAND"
48
- end
49
-
50
- it "#desc_markdown" do
51
- puts page.desc_markdown
52
- expect(page.desc_markdown).to include "# Description"
53
- end
54
-
55
- # Think it is better to hide subcommand options_markdown at the top-level.
56
- # User will see the optoins once they click into the subcommand.
57
- it "#options_markdown" do
58
- expect(page.options_markdown).to include("")
59
- end
60
-
61
- it "#subcommand_list" do
62
- expect(page.doc).to include("# Subcommands")
63
- # puts page.subcommand_list # uncomment to see generated list for debugging
64
- end
65
-
66
- it "#doc" do
67
- expect(page.doc).to include("# Description")
68
- # puts page.doc # uncomment to see generated page for debugging
69
- end
70
- end
71
-
72
- ################
73
- # rest are edge cases
74
- context "summary" do
75
- let(:command) { "summary" }
76
-
77
- # empty options_markdown
78
- it "#options_markdown" do
79
- expect(page.options_markdown).to eq ""
80
- end
81
-
82
- it "#doc" do
83
- expect(page.doc).to include("# Description")
84
- # puts page.doc # uncomment to see generated page for debugging
85
- end
86
- end
87
- end