cli-template 3.5.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +7 -1
- data/cli-template.gemspec +3 -2
- data/exe/cli-template +2 -2
- data/lib/cli-template.rb +1 -12
- data/lib/cli_template.rb +8 -0
- data/lib/cli_template/autoloader.rb +22 -0
- data/lib/{cli-template → cli_template}/cli.rb +0 -0
- data/lib/{cli-template → cli_template}/command.rb +0 -0
- data/lib/{cli-template → cli_template}/help.rb +0 -0
- data/lib/{cli-template → cli_template}/help/new.md +0 -0
- data/lib/{cli-template → cli_template}/helper.rb +0 -0
- data/lib/{cli-template → cli_template}/new.rb +1 -1
- data/lib/{cli-template → cli_template}/sequence.rb +28 -1
- data/lib/{cli-template → cli_template}/version.rb +1 -1
- data/lib/templates/colon_namespaces/%project_name%.gemspec.tt +1 -0
- data/lib/templates/colon_namespaces/spec/lib/cli_spec.rb.tt +0 -12
- data/lib/templates/default/%project_name%.gemspec.tt +1 -0
- data/lib/templates/default/{LICENSE.txt → LICENSE.txt.tt} +1 -1
- data/lib/templates/default/exe/%project_name%.tt +1 -1
- data/lib/templates/default/lib/%project_name%.rb.tt +3 -7
- data/lib/templates/default/lib/%underscored_name%/autoloader.rb.tt +24 -0
- data/lib/templates/default/lib/%underscored_name%/cli.rb.tt +2 -1
- data/lib/templates/default/lib/%underscored_name%/completer.rb.tt +0 -2
- data/lib/templates/default/spec/lib/cli_spec.rb.tt +0 -10
- metadata +30 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b53337284c8b96dbc2542077b822c17bc84aef700324434f2516f3dc1e49fec8
|
4
|
+
data.tar.gz: 8919ffcd06b6080fb07e098f495180379c8de7fecf6f7463d22292eb15c89c14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 463553b6d137103f0fdcb7c0ee79e5f8852116442940f3d86385e7e05473cbc0360cb0f90bb94ceeff6e5ea73745a9f74ef717620e5d4861266196cb3c4c27a8
|
7
|
+
data.tar.gz: be52eb5f0f27e5bb0e1cd9c5b789df36829329eb82bae2a09a9fc401196a5c8fdcc563a6c7d502e031a0afd4ff4254339c3149ef98fcaca7375160580e0775b5
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,9 @@
|
|
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.0.0]
|
7
|
+
- use zeitwerk for autoload
|
8
|
+
|
6
9
|
## [3.5.1]
|
7
10
|
- #4 from sco11morgan/move-activesupport-to-dev
|
8
11
|
- ensure docs/_includes is created
|
data/Gemfile
CHANGED
@@ -3,4 +3,10 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in cli-template.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
|
6
|
+
# Some gems are included because the generated project contains these gems
|
7
|
+
# We use bundle exec to run specs in circleci.
|
8
|
+
# This workaround ensures those gems are also installed with the first bundle install.
|
9
|
+
group :test do
|
10
|
+
gem "codeclimate-test-reporter", require: nil
|
11
|
+
gem "cli_markdown"
|
12
|
+
end
|
data/cli-template.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'cli_template/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "cli-template"
|
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "thor"
|
22
21
|
spec.add_dependency "rainbow"
|
22
|
+
spec.add_dependency "thor"
|
23
|
+
spec.add_dependency "zeitwerk"
|
23
24
|
|
24
25
|
spec.add_development_dependency "activesupport"
|
25
26
|
spec.add_development_dependency "bundler"
|
data/exe/cli-template
CHANGED
data/lib/cli-template.rb
CHANGED
@@ -1,12 +1 @@
|
|
1
|
-
|
2
|
-
require "cli-template/version"
|
3
|
-
|
4
|
-
module CliTemplate
|
5
|
-
autoload :Help, 'cli-template/help'
|
6
|
-
autoload :CLI, 'cli-template/cli'
|
7
|
-
autoload :Command, 'cli-template/command'
|
8
|
-
autoload :Version, 'cli-template/version'
|
9
|
-
autoload :Sequence, 'cli-template/sequence'
|
10
|
-
autoload :New, 'cli-template/new'
|
11
|
-
autoload :Helper, 'cli-template/helper'
|
12
|
-
end
|
1
|
+
require_relative "cli_template"
|
data/lib/cli_template.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "zeitwerk"
|
2
|
+
|
3
|
+
module CliTemplate
|
4
|
+
class Autoloader
|
5
|
+
class Inflector < Zeitwerk::Inflector
|
6
|
+
def camelize(basename, _abspath)
|
7
|
+
map = { cli: "CLI", version: "VERSION" }
|
8
|
+
map[basename.to_sym] || super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def setup
|
14
|
+
loader = Zeitwerk::Loader.new
|
15
|
+
loader.inflector = Inflector.new
|
16
|
+
loader.push_dir(File.dirname(__dir__)) # lib
|
17
|
+
loader.ignore("#{File.dirname(__dir__)}/cli-template.rb")
|
18
|
+
loader.setup
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -11,6 +11,7 @@ module CliTemplate
|
|
11
11
|
[:repo, desc: "GitHub repo to use. Format: user/repo"],
|
12
12
|
[:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
|
13
13
|
[:git, type: :boolean, default: true, desc: "Git initialize the project"],
|
14
|
+
[:subcommand, type: :boolean, default: false, desc: "Include subcommand example"],
|
14
15
|
]
|
15
16
|
end
|
16
17
|
|
@@ -56,7 +57,6 @@ Test the CLI:
|
|
56
57
|
cd #{project_name}
|
57
58
|
bundle
|
58
59
|
exe/#{project_name} hello # top-level commands
|
59
|
-
exe/#{project_name} sub:goodbye # sub commands
|
60
60
|
bundle exec rspec
|
61
61
|
|
62
62
|
To publish your CLI as a gem:
|
@@ -38,7 +38,34 @@ private
|
|
38
38
|
|
39
39
|
def copy_project
|
40
40
|
puts "Creating new project called #{project_name}."
|
41
|
-
directory ".", project_name
|
41
|
+
directory ".", project_name, copy_options
|
42
|
+
if project_name.include?("-")
|
43
|
+
dashed_path = "#{project_name}/lib/#{project_name}.rb"
|
44
|
+
underscored_path = "#{project_name}/lib/#{underscored_name}.rb"
|
45
|
+
|
46
|
+
FileUtils.mv(dashed_path, underscored_path)
|
47
|
+
IO.write(dashed_path, <<~EOL)
|
48
|
+
require_relative "#{underscored_name}"
|
49
|
+
EOL
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def copy_options
|
54
|
+
excludes = if @options[:subcommand]
|
55
|
+
[]
|
56
|
+
else
|
57
|
+
%w[
|
58
|
+
help/sub
|
59
|
+
sub.rb
|
60
|
+
]
|
61
|
+
end
|
62
|
+
|
63
|
+
if excludes.empty?
|
64
|
+
{}
|
65
|
+
else
|
66
|
+
pattern = Regexp.new(excludes.join('|'))
|
67
|
+
{exclude_pattern: pattern }
|
68
|
+
end
|
42
69
|
end
|
43
70
|
|
44
71
|
def git_installed?
|
@@ -11,27 +11,15 @@ describe <%= project_class_name %>::CLI do
|
|
11
11
|
expect(out).to include("from: Tung\nHello world")
|
12
12
|
end
|
13
13
|
|
14
|
-
it "goodbye" do
|
15
|
-
out = execute("exe/<%= project_name %> sub:goodbye world #{@args}")
|
16
|
-
expect(out).to include("from: Tung\nGoodbye world")
|
17
|
-
end
|
18
|
-
|
19
14
|
it "completions" do
|
20
15
|
out = execute("exe/<%= project_name %> completions")
|
21
16
|
expect(out).to include("hello")
|
22
|
-
expect(out).to include("sub:goodbye")
|
23
17
|
|
24
18
|
out = execute("exe/<%= project_name %> completions hello")
|
25
19
|
expect(out).to include("name")
|
26
20
|
|
27
21
|
out = execute("exe/<%= project_name %> completions hello name")
|
28
22
|
expect(out).to include("--from")
|
29
|
-
|
30
|
-
out = execute("exe/<%= project_name %> completions sub:goodbye")
|
31
|
-
expect(out).to include("name")
|
32
|
-
|
33
|
-
out = execute("exe/<%= project_name %> completions sub:goodbye name")
|
34
|
-
expect(out).to include("--from")
|
35
23
|
end
|
36
24
|
end
|
37
25
|
end
|
@@ -2,13 +2,9 @@ $:.unshift(File.expand_path("../", __FILE__))
|
|
2
2
|
require "<%= underscored_name %>/version"
|
3
3
|
require "rainbow/ext/string"
|
4
4
|
|
5
|
+
require "<%= underscored_name %>/autoloader"
|
6
|
+
<%= project_class_name %>::Autoloader.setup
|
7
|
+
|
5
8
|
module <%= project_class_name %>
|
6
9
|
class Error < StandardError; end
|
7
|
-
|
8
|
-
autoload :CLI, "<%= underscored_name %>/cli"
|
9
|
-
autoload :Command, "<%= underscored_name %>/command"
|
10
|
-
autoload :Completer, "<%= underscored_name %>/completer"
|
11
|
-
autoload :Completion, "<%= underscored_name %>/completion"
|
12
|
-
autoload :Help, "<%= underscored_name %>/help"
|
13
|
-
autoload :Sub, "<%= underscored_name %>/sub"
|
14
10
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "zeitwerk"
|
2
|
+
|
3
|
+
module <%= project_class_name %>
|
4
|
+
class Autoloader
|
5
|
+
class Inflector < Zeitwerk::Inflector
|
6
|
+
def camelize(basename, _abspath)
|
7
|
+
map = { cli: "CLI", version: "VERSION" }
|
8
|
+
map[basename.to_sym] || super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def setup
|
14
|
+
loader = Zeitwerk::Loader.new
|
15
|
+
loader.inflector = Inflector.new
|
16
|
+
loader.push_dir(File.dirname(__dir__)) # lib
|
17
|
+
<% if project_name.include?('-') -%>
|
18
|
+
loader.ignore("#{File.dirname(__dir__)}/<%= project_name %>.rb")
|
19
|
+
<% end -%>
|
20
|
+
loader.setup
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -10,10 +10,11 @@ module <%= project_class_name %>
|
|
10
10
|
puts "from: #{options[:from]}" if options[:from]
|
11
11
|
puts "Hello #{name}"
|
12
12
|
end
|
13
|
-
|
13
|
+
<% if options[:subcommand] -%>
|
14
14
|
desc "sub SUBCOMMAND", "sub subcommands"
|
15
15
|
long_desc Help.text(:sub)
|
16
16
|
subcommand "sub", Sub
|
17
|
+
<% end -%>
|
17
18
|
|
18
19
|
desc "completion *PARAMS", "Prints words for auto-completion."
|
19
20
|
long_desc Help.text("completion")
|
@@ -70,8 +70,6 @@ Auto-completion accounts for each of these type of commands.
|
|
70
70
|
=end
|
71
71
|
module <%= project_class_name %>
|
72
72
|
class Completer
|
73
|
-
autoload :Script, '<%= underscored_name %>/completer/script'
|
74
|
-
|
75
73
|
def initialize(command_class, *params)
|
76
74
|
@params = params
|
77
75
|
@current_command = @params[0]
|
@@ -11,22 +11,12 @@ describe <%= project_class_name %>::CLI do
|
|
11
11
|
expect(out).to include("from: Tung\nHello world")
|
12
12
|
end
|
13
13
|
|
14
|
-
it "goodbye" do
|
15
|
-
out = execute("exe/<%= project_name %> sub goodbye world #{@args}")
|
16
|
-
expect(out).to include("from: Tung\nGoodbye world")
|
17
|
-
end
|
18
|
-
|
19
14
|
commands = {
|
20
15
|
"hell" => "hello",
|
21
16
|
"hello" => "name",
|
22
17
|
"hello -" => "--from",
|
23
18
|
"hello name" => "--from",
|
24
19
|
"hello name --" => "--from",
|
25
|
-
"sub goodb" => "goodbye",
|
26
|
-
"sub goodbye" => "name",
|
27
|
-
"sub goodbye name" => "--from",
|
28
|
-
"sub goodbye name --" => "--from",
|
29
|
-
"sub goodbye name --from" => "--help",
|
30
20
|
}
|
31
21
|
commands.each do |command, expected_word|
|
32
22
|
it "completion #{command}" do
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli-template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.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: 2019-
|
11
|
+
date: 2019-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rainbow
|
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: thor
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,7 +39,7 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: zeitwerk
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -156,14 +170,16 @@ files:
|
|
156
170
|
- cli-template.gemspec
|
157
171
|
- exe/cli-template
|
158
172
|
- lib/cli-template.rb
|
159
|
-
- lib/
|
160
|
-
- lib/
|
161
|
-
- lib/cli
|
162
|
-
- lib/
|
163
|
-
- lib/
|
164
|
-
- lib/
|
165
|
-
- lib/
|
166
|
-
- lib/
|
173
|
+
- lib/cli_template.rb
|
174
|
+
- lib/cli_template/autoloader.rb
|
175
|
+
- lib/cli_template/cli.rb
|
176
|
+
- lib/cli_template/command.rb
|
177
|
+
- lib/cli_template/help.rb
|
178
|
+
- lib/cli_template/help/new.md
|
179
|
+
- lib/cli_template/helper.rb
|
180
|
+
- lib/cli_template/new.rb
|
181
|
+
- lib/cli_template/sequence.rb
|
182
|
+
- lib/cli_template/version.rb
|
167
183
|
- lib/templates/colon_namespaces/%project_name%.gemspec.tt
|
168
184
|
- lib/templates/colon_namespaces/.gitignore
|
169
185
|
- lib/templates/colon_namespaces/.rspec
|
@@ -199,11 +215,12 @@ files:
|
|
199
215
|
- lib/templates/default/CHANGELOG.md
|
200
216
|
- lib/templates/default/Gemfile.tt
|
201
217
|
- lib/templates/default/Guardfile
|
202
|
-
- lib/templates/default/LICENSE.txt
|
218
|
+
- lib/templates/default/LICENSE.txt.tt
|
203
219
|
- lib/templates/default/README.md.tt
|
204
220
|
- lib/templates/default/Rakefile.tt
|
205
221
|
- lib/templates/default/exe/%project_name%.tt
|
206
222
|
- lib/templates/default/lib/%project_name%.rb.tt
|
223
|
+
- lib/templates/default/lib/%underscored_name%/autoloader.rb.tt
|
207
224
|
- lib/templates/default/lib/%underscored_name%/cli.rb.tt
|
208
225
|
- lib/templates/default/lib/%underscored_name%/command.rb.tt
|
209
226
|
- lib/templates/default/lib/%underscored_name%/completer.rb.tt
|
@@ -239,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
256
|
- !ruby/object:Gem::Version
|
240
257
|
version: '0'
|
241
258
|
requirements: []
|
242
|
-
rubygems_version: 3.0.
|
259
|
+
rubygems_version: 3.0.3
|
243
260
|
signing_key:
|
244
261
|
specification_version: 4
|
245
262
|
summary: Generate a CLI tool quickly
|