cli-template 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +58 -0
- data/.gitignore +17 -0
- data/.rspec +4 -0
- data/CHANGELOG.md +48 -0
- data/Gemfile +6 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +32 -0
- data/cli-template.gemspec +32 -0
- data/exe/cli-template +9 -0
- data/lib/cli-template.rb +12 -0
- data/lib/cli-template/cli.rb +17 -0
- data/lib/cli-template/command.rb +47 -0
- data/lib/cli-template/help.rb +9 -0
- data/lib/cli-template/help/new.md +4 -0
- data/lib/cli-template/helpers.rb +12 -0
- data/lib/cli-template/new.rb +74 -0
- data/lib/cli-template/sequence.rb +45 -0
- data/lib/cli-template/version.rb +3 -0
- data/lib/templates/skeleton/%project_name%.gemspec.tt +30 -0
- data/lib/templates/skeleton/.gitignore +16 -0
- data/lib/templates/skeleton/.rspec +2 -0
- data/lib/templates/skeleton/CHANGELOG.md +7 -0
- data/lib/templates/skeleton/Gemfile.tt +6 -0
- data/lib/templates/skeleton/Guardfile +19 -0
- data/lib/templates/skeleton/LICENSE.txt +22 -0
- data/lib/templates/skeleton/README.md.tt +47 -0
- data/lib/templates/skeleton/Rakefile +6 -0
- data/lib/templates/skeleton/exe/%project_name%.tt +14 -0
- data/lib/templates/skeleton/lib/%project_name%.rb.tt +10 -0
- data/lib/templates/skeleton/lib/%underscored_name%/cli.rb.tt +170 -0
- data/lib/templates/skeleton/lib/%underscored_name%/command.rb.tt +164 -0
- data/lib/templates/skeleton/lib/%underscored_name%/help.rb.tt +9 -0
- data/lib/templates/skeleton/lib/%underscored_name%/help/hello.md.tt +3 -0
- data/lib/templates/skeleton/lib/%underscored_name%/help/sub/goodbye.md.tt +3 -0
- data/lib/templates/skeleton/lib/%underscored_name%/main.rb.tt +21 -0
- data/lib/templates/skeleton/lib/%underscored_name%/rake_command.rb.tt +63 -0
- data/lib/templates/skeleton/lib/%underscored_name%/sub.rb.tt +12 -0
- data/lib/templates/skeleton/lib/%underscored_name%/version.rb.tt +3 -0
- data/lib/templates/skeleton/spec/lib/cli_spec.rb.tt +24 -0
- data/lib/templates/skeleton/spec/spec_helper.rb.tt +29 -0
- data/spec/lib/cli_spec.rb +61 -0
- data/spec/spec_helper.rb +33 -0
- metadata +217 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
module <%= project_class_name %>
|
4
|
+
class Main < Command
|
5
|
+
class_option :verbose, type: :boolean
|
6
|
+
class_option :noop, type: :boolean
|
7
|
+
|
8
|
+
desc "hello NAME", "say hello to NAME"
|
9
|
+
long_desc Help.text(:hello)
|
10
|
+
option :from, desc: "from person"
|
11
|
+
def hello(name="you")
|
12
|
+
puts "from: #{options[:from]}" if options[:from]
|
13
|
+
puts "Hello #{name}"
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "version", "prints version"
|
17
|
+
def version
|
18
|
+
puts VERSION
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "rake"
|
2
|
+
|
3
|
+
class <%= project_class_name %>::RakeCommand
|
4
|
+
class << self
|
5
|
+
# Same signature as <%= project_class_name %>::Command.perform.
|
6
|
+
def perform(namespaced_command, thor_args)
|
7
|
+
if thor_args.first == "help"
|
8
|
+
puts help_message(namespaced_command)
|
9
|
+
return
|
10
|
+
end
|
11
|
+
|
12
|
+
require_rake
|
13
|
+
|
14
|
+
ARGV.unshift(namespaced_command) # Prepend the task, so Rake knows how to run it.
|
15
|
+
|
16
|
+
rake.standard_exception_handling do
|
17
|
+
rake.init("<%= project_name %>")
|
18
|
+
rake.load_rakefile
|
19
|
+
rake.top_level
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Useful for CLI.lookup.
|
24
|
+
def namespaced_commands
|
25
|
+
formatted_rake_tasks(true).map(&:first)
|
26
|
+
end
|
27
|
+
|
28
|
+
def formatted_rake_tasks(all=false)
|
29
|
+
rake_tasks(all).map do |t|
|
30
|
+
comment = "# #{t.comment}" if t.comment
|
31
|
+
[ t.name_with_args, comment ]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def rake_tasks(all=false)
|
36
|
+
require_rake
|
37
|
+
|
38
|
+
Rake::TaskManager.record_task_metadata = true
|
39
|
+
rake.instance_variable_set(:@name, "<%= project_name %>")
|
40
|
+
load "Rakefile" if File.exist?("Rakefile")
|
41
|
+
tasks = rake.tasks
|
42
|
+
tasks = tasks.select(&:comment) unless all
|
43
|
+
tasks
|
44
|
+
end
|
45
|
+
|
46
|
+
def help_message(namespaced_command)
|
47
|
+
task = rake_tasks(true).find { |t| t.name == namespaced_command }
|
48
|
+
message = "Help provided by rake task:\n\n"
|
49
|
+
message << "<%= project_name %> #{task.name_with_args.dup}\n"
|
50
|
+
message << " #{task.full_comment}"
|
51
|
+
message
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def rake
|
56
|
+
Rake.application
|
57
|
+
end
|
58
|
+
|
59
|
+
def require_rake
|
60
|
+
require "rake" # Defer booting Rake until we know it's needed.
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module <%= project_class_name %>
|
2
|
+
class Sub < Command
|
3
|
+
|
4
|
+
desc "goodbye NAME", "say goodbye to NAME"
|
5
|
+
long_desc Help.text("sub:goodbye")
|
6
|
+
option :from, desc: "from person"
|
7
|
+
def goodbye(name="you")
|
8
|
+
puts "from: #{options[:from]}" if options[:from]
|
9
|
+
puts "Goodbye #{name}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# to run specs with what"s remembered from vcr
|
4
|
+
# $ rake
|
5
|
+
#
|
6
|
+
# to run specs with new fresh data from aws api calls
|
7
|
+
# $ rake clean:vcr ; time rake
|
8
|
+
describe <%= project_class_name %>::CLI do
|
9
|
+
before(:all) do
|
10
|
+
@args = "--from Tung"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "<%= project_name %>" do
|
14
|
+
it "should hello world" do
|
15
|
+
out = execute("exe/<%= project_name %> hello world #{@args}")
|
16
|
+
expect(out).to include("from: Tung\nHello world")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should goodbye world" do
|
20
|
+
out = execute("exe/<%= project_name %> sub:goodbye world #{@args}")
|
21
|
+
expect(out).to include("from: Tung\nGoodbye world")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
ENV["TEST"] = "1"
|
2
|
+
|
3
|
+
# CodeClimate test coverage: https://docs.codeclimate.com/docs/configuring-test-coverage
|
4
|
+
# require 'simplecov'
|
5
|
+
# SimpleCov.start
|
6
|
+
|
7
|
+
require "pp"
|
8
|
+
|
9
|
+
root = File.expand_path("../../", __FILE__)
|
10
|
+
require "#{root}/lib/<%= project_name %>"
|
11
|
+
|
12
|
+
module Helpers
|
13
|
+
def execute(cmd)
|
14
|
+
puts "Running: #{cmd}" if show_command?
|
15
|
+
out = `#{cmd}`
|
16
|
+
puts out if show_command?
|
17
|
+
out
|
18
|
+
end
|
19
|
+
|
20
|
+
# Added SHOW_COMMAND because DEBUG is also used by other libraries like
|
21
|
+
# bundler and it shows its internal debugging logging also.
|
22
|
+
def show_command?
|
23
|
+
ENV['DEBUG'] || ENV['SHOW_COMMAND']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.configure do |c|
|
28
|
+
c.include Helpers
|
29
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# This spec tests the generator with various forms of project names:
|
4
|
+
#
|
5
|
+
# hello, my_cli, my-cli, MyCLI
|
6
|
+
#
|
7
|
+
# The tests shell out and execute the new command to ensures a high level of
|
8
|
+
# confidence that the CLI generator works in real life.
|
9
|
+
#
|
10
|
+
# It also executes the generates specs of the new project to ensure specs
|
11
|
+
# also pass.
|
12
|
+
#
|
13
|
+
# Because it shells out tests take about 20 seconds to run this spec file.
|
14
|
+
describe CliTemplate::CLI do
|
15
|
+
before(:all) do
|
16
|
+
@args = "--noop"
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "new" do
|
20
|
+
context("simple single name") do
|
21
|
+
it "should generate" do
|
22
|
+
out = execute("cd tmp && ../exe/cli-template new hello #{@args}")
|
23
|
+
expect(out).to include("Creating new project called hello")
|
24
|
+
expect(out).to include("You have successfully created a CLI project")
|
25
|
+
out = execute("cd tmp/hello && rake")
|
26
|
+
expect(out).to include("0 failures")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context("underscored name") do
|
31
|
+
it "should generate" do
|
32
|
+
out = execute("cd tmp && ../exe/cli-template new my_cli #{@args}")
|
33
|
+
expect(out).to include("Creating new project called my_cli")
|
34
|
+
expect(out).to include("You have successfully created a CLI project")
|
35
|
+
out = execute("cd tmp/my_cli && rake")
|
36
|
+
expect(out).to include("0 failures")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context("dasherized name") do
|
41
|
+
it "should generate" do
|
42
|
+
out = execute("cd tmp && ../exe/cli-template new my-cli #{@args}")
|
43
|
+
expect(out).to include("Creating new project called my-cli")
|
44
|
+
expect(out).to include("You have successfully created a CLI project")
|
45
|
+
out = execute("cd tmp/my-cli && rake")
|
46
|
+
expect(out).to include("0 failures")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# CamelCase is ugly :(
|
51
|
+
context("simple CamelCase name") do
|
52
|
+
it "should generate" do
|
53
|
+
out = execute("cd tmp && ../exe/cli-template new MyCli #{@args}")
|
54
|
+
expect(out).to include("Creating new project called MyCli")
|
55
|
+
expect(out).to include("You have successfully created a CLI project")
|
56
|
+
out = execute("cd tmp/MyCli && rake")
|
57
|
+
expect(out).to include("0 failures")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
ENV['TEST'] = '1'
|
2
|
+
|
3
|
+
# CodeClimate test coverage: https://docs.codeclimate.com/docs/configuring-test-coverage
|
4
|
+
# require 'simplecov'
|
5
|
+
# SimpleCov.start
|
6
|
+
|
7
|
+
require "pp"
|
8
|
+
|
9
|
+
root = File.expand_path('../../', __FILE__)
|
10
|
+
require "#{root}/lib/cli-template"
|
11
|
+
|
12
|
+
module Helpers
|
13
|
+
def execute(cmd)
|
14
|
+
puts "Running: #{cmd}" if show_command?
|
15
|
+
out = `#{cmd}`
|
16
|
+
puts out if show_command?
|
17
|
+
out
|
18
|
+
end
|
19
|
+
|
20
|
+
# Added SHOW_COMMAND because DEBUG is also used by other libraries like
|
21
|
+
# bundler and it shows its internal debugging logging also.
|
22
|
+
def show_command?
|
23
|
+
ENV['DEBUG'] || ENV['SHOW_COMMAND']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.configure do |c|
|
28
|
+
c.include Helpers
|
29
|
+
c.before(:all) do
|
30
|
+
FileUtils.rm_rf("tmp")
|
31
|
+
FileUtils.mkdir_p("tmp")
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cli-template
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tung Nguyen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: byebug
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Generate a CLI tool quickly
|
140
|
+
email:
|
141
|
+
- tongueroo@gmail.com
|
142
|
+
executables:
|
143
|
+
- cli-template
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".circleci/config.yml"
|
148
|
+
- ".gitignore"
|
149
|
+
- ".rspec"
|
150
|
+
- CHANGELOG.md
|
151
|
+
- Gemfile
|
152
|
+
- Guardfile
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- cli-template.gemspec
|
157
|
+
- exe/cli-template
|
158
|
+
- lib/cli-template.rb
|
159
|
+
- lib/cli-template/cli.rb
|
160
|
+
- lib/cli-template/command.rb
|
161
|
+
- lib/cli-template/help.rb
|
162
|
+
- lib/cli-template/help/new.md
|
163
|
+
- lib/cli-template/helpers.rb
|
164
|
+
- lib/cli-template/new.rb
|
165
|
+
- lib/cli-template/sequence.rb
|
166
|
+
- lib/cli-template/version.rb
|
167
|
+
- lib/templates/skeleton/%project_name%.gemspec.tt
|
168
|
+
- lib/templates/skeleton/.gitignore
|
169
|
+
- lib/templates/skeleton/.rspec
|
170
|
+
- lib/templates/skeleton/CHANGELOG.md
|
171
|
+
- lib/templates/skeleton/Gemfile.tt
|
172
|
+
- lib/templates/skeleton/Guardfile
|
173
|
+
- lib/templates/skeleton/LICENSE.txt
|
174
|
+
- lib/templates/skeleton/README.md.tt
|
175
|
+
- lib/templates/skeleton/Rakefile
|
176
|
+
- lib/templates/skeleton/exe/%project_name%.tt
|
177
|
+
- lib/templates/skeleton/lib/%project_name%.rb.tt
|
178
|
+
- lib/templates/skeleton/lib/%underscored_name%/cli.rb.tt
|
179
|
+
- lib/templates/skeleton/lib/%underscored_name%/command.rb.tt
|
180
|
+
- lib/templates/skeleton/lib/%underscored_name%/help.rb.tt
|
181
|
+
- lib/templates/skeleton/lib/%underscored_name%/help/hello.md.tt
|
182
|
+
- lib/templates/skeleton/lib/%underscored_name%/help/sub/goodbye.md.tt
|
183
|
+
- lib/templates/skeleton/lib/%underscored_name%/main.rb.tt
|
184
|
+
- lib/templates/skeleton/lib/%underscored_name%/rake_command.rb.tt
|
185
|
+
- lib/templates/skeleton/lib/%underscored_name%/sub.rb.tt
|
186
|
+
- lib/templates/skeleton/lib/%underscored_name%/version.rb.tt
|
187
|
+
- lib/templates/skeleton/spec/lib/cli_spec.rb.tt
|
188
|
+
- lib/templates/skeleton/spec/spec_helper.rb.tt
|
189
|
+
- spec/lib/cli_spec.rb
|
190
|
+
- spec/spec_helper.rb
|
191
|
+
homepage: https://gitub.com/tongueroo/cli-template
|
192
|
+
licenses:
|
193
|
+
- MIT
|
194
|
+
metadata: {}
|
195
|
+
post_install_message:
|
196
|
+
rdoc_options: []
|
197
|
+
require_paths:
|
198
|
+
- lib
|
199
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
requirements: []
|
210
|
+
rubyforge_project:
|
211
|
+
rubygems_version: 2.7.3
|
212
|
+
signing_key:
|
213
|
+
specification_version: 4
|
214
|
+
summary: Generate a CLI tool quickly
|
215
|
+
test_files:
|
216
|
+
- spec/lib/cli_spec.rb
|
217
|
+
- spec/spec_helper.rb
|