cli-kit 3.3.0 → 5.0.0
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 +4 -4
- data/.github/dependabot.yml +10 -0
- data/.github/workflows/cla.yml +22 -0
- data/.github/workflows/ruby.yml +64 -0
- data/.gitignore +2 -0
- data/.rubocop.sorbet.yml +47 -0
- data/.rubocop.yml +22 -13
- data/Gemfile +13 -3
- data/Gemfile.lock +110 -28
- data/README.md +46 -3
- data/Rakefile +28 -1
- data/bin/console +3 -3
- data/bin/onchange +30 -0
- data/bin/tapioca +29 -0
- data/bin/test_gen +4 -1
- data/bin/testunit +3 -2
- data/cli-kit.gemspec +7 -6
- data/dev.yml +35 -3
- data/examples/minimal/example.rb +5 -3
- data/examples/single-file/example.rb +25 -35
- data/gen/lib/gen/commands/help.rb +8 -10
- data/gen/lib/gen/commands/new.rb +23 -9
- data/gen/lib/gen/commands.rb +21 -9
- data/gen/lib/gen/entry_point.rb +12 -3
- data/gen/lib/gen/generator.rb +39 -18
- data/gen/lib/gen/help.rb +63 -0
- data/gen/lib/gen.rb +18 -23
- data/gen/template/bin/update-deps +2 -2
- data/gen/template/lib/__app__/commands.rb +1 -4
- data/gen/template/lib/__app__.rb +8 -17
- data/gen/template/test/example_test.rb +1 -1
- data/lib/cli/kit/args/definition.rb +344 -0
- data/lib/cli/kit/args/evaluation.rb +245 -0
- data/lib/cli/kit/args/parser/node.rb +132 -0
- data/lib/cli/kit/args/parser.rb +129 -0
- data/lib/cli/kit/args/tokenizer.rb +133 -0
- data/lib/cli/kit/args.rb +16 -0
- data/lib/cli/kit/base_command.rb +17 -32
- data/lib/cli/kit/command_help.rb +271 -0
- data/lib/cli/kit/command_registry.rb +69 -17
- data/lib/cli/kit/config.rb +30 -25
- data/lib/cli/kit/core_ext.rb +30 -0
- data/lib/cli/kit/error_handler.rb +134 -67
- data/lib/cli/kit/executor.rb +39 -20
- data/lib/cli/kit/ini.rb +32 -39
- data/lib/cli/kit/levenshtein.rb +12 -4
- data/lib/cli/kit/logger.rb +23 -3
- data/lib/cli/kit/opts.rb +301 -0
- data/lib/cli/kit/resolver.rb +10 -2
- data/lib/cli/kit/sorbet_runtime_stub.rb +156 -0
- data/lib/cli/kit/support/test_helper.rb +31 -22
- data/lib/cli/kit/support.rb +2 -0
- data/lib/cli/kit/system.rb +217 -48
- data/lib/cli/kit/util.rb +52 -107
- data/lib/cli/kit/version.rb +3 -1
- data/lib/cli/kit.rb +104 -8
- metadata +35 -22
- data/.github/probots.yml +0 -2
- data/.travis.yml +0 -14
- data/lib/cli/kit/autocall.rb +0 -21
- data/lib/cli/kit/ruby_backports/enumerable.rb +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e576da52278c6b0596840691bffbb12546b54bf2238145455a45333d6101f773
|
|
4
|
+
data.tar.gz: 24243f1a2d66ad3b12fb2728b73b608038950d958ffc31dc0ab7951c3714533a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e7f4f5c4cc6620a2d98eca89e85ad57e6a9a0bd94ec704503ac0c9ba84f631984beb7c71c60e8b24ddbd2c4cf88b30cc298d3b05009f565450348a5b82c8d7f
|
|
7
|
+
data.tar.gz: ac1c63ad107ca13fda07413a17054a17bb69ec6ae793f2a0abb97a5c2616c15fe7aaeaf7c3328b7ce035136dd72007df51fe7f5aab15e0c90199ede7ddd8d1e0
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Contributor License Agreement (CLA)
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request_target:
|
|
5
|
+
types: [opened, synchronize]
|
|
6
|
+
issue_comment:
|
|
7
|
+
types: [created]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
cla:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
if: |
|
|
13
|
+
(github.event.issue.pull_request
|
|
14
|
+
&& !github.event.issue.pull_request.merged_at
|
|
15
|
+
&& contains(github.event.comment.body, 'signed')
|
|
16
|
+
)
|
|
17
|
+
|| (github.event.pull_request && !github.event.pull_request.merged)
|
|
18
|
+
steps:
|
|
19
|
+
- uses: Shopify/shopify-cla-action@v1
|
|
20
|
+
with:
|
|
21
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
22
|
+
cla-token: ${{ secrets.CLA_TOKEN }}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
name: Ruby
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
|
|
7
|
+
style:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v2
|
|
11
|
+
- name: Set up Ruby
|
|
12
|
+
uses: ruby/setup-ruby@v1
|
|
13
|
+
with:
|
|
14
|
+
ruby-version: '2.7'
|
|
15
|
+
bundler-cache: true
|
|
16
|
+
- name: Check style
|
|
17
|
+
run: bundle exec rake style
|
|
18
|
+
|
|
19
|
+
typecheck:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v2
|
|
23
|
+
- name: Set up Ruby
|
|
24
|
+
uses: ruby/setup-ruby@v1
|
|
25
|
+
with:
|
|
26
|
+
ruby-version: '2.7'
|
|
27
|
+
bundler-cache: true
|
|
28
|
+
- name: Typecheck
|
|
29
|
+
run: bundle exec srb tc
|
|
30
|
+
|
|
31
|
+
test:
|
|
32
|
+
strategy:
|
|
33
|
+
matrix:
|
|
34
|
+
os: [macos-latest, ubuntu-latest]
|
|
35
|
+
ruby-version: ['2.7', '3.0']
|
|
36
|
+
|
|
37
|
+
runs-on: ${{ matrix.os }}
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v2
|
|
40
|
+
- name: Set up Ruby
|
|
41
|
+
uses: ruby/setup-ruby@v1
|
|
42
|
+
with:
|
|
43
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
44
|
+
bundler-cache: true
|
|
45
|
+
- name: Run tests
|
|
46
|
+
run: bundle exec rake test
|
|
47
|
+
|
|
48
|
+
test-windows:
|
|
49
|
+
strategy:
|
|
50
|
+
matrix:
|
|
51
|
+
ruby-version: ['2.7', '3.0']
|
|
52
|
+
|
|
53
|
+
runs-on: windows-latest
|
|
54
|
+
env:
|
|
55
|
+
BUNDLE_WITHOUT: typecheck
|
|
56
|
+
steps:
|
|
57
|
+
- uses: actions/checkout@v2
|
|
58
|
+
- name: Set up Ruby
|
|
59
|
+
uses: ruby/setup-ruby@v1
|
|
60
|
+
with:
|
|
61
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
62
|
+
bundler-cache: true
|
|
63
|
+
- name: Run tests
|
|
64
|
+
run: bundle exec rake test
|
data/.gitignore
CHANGED
data/.rubocop.sorbet.yml
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Sorbet:
|
|
2
|
+
Enabled: true
|
|
3
|
+
|
|
4
|
+
Sorbet/ValidSigil:
|
|
5
|
+
Enabled: true
|
|
6
|
+
Exclude:
|
|
7
|
+
- lib/cli/kit/sorbet_runtime_stub.rb
|
|
8
|
+
|
|
9
|
+
Sorbet/FalseSigil:
|
|
10
|
+
Enabled: false
|
|
11
|
+
|
|
12
|
+
Sorbet/TrueSigil:
|
|
13
|
+
Enabled: true
|
|
14
|
+
Include:
|
|
15
|
+
- "**/*.rb"
|
|
16
|
+
- "**/*.rbi"
|
|
17
|
+
- "**/*.rake"
|
|
18
|
+
- "**/*.ru"
|
|
19
|
+
Exclude:
|
|
20
|
+
- lib/cli/kit/sorbet_runtime_stub.rb
|
|
21
|
+
- "test/**/*"
|
|
22
|
+
- "lib/cli/kit/support/test_helper.rb"
|
|
23
|
+
|
|
24
|
+
Sorbet/EnforceSigilOrder:
|
|
25
|
+
Enabled: true
|
|
26
|
+
|
|
27
|
+
Sorbet/EnforceSignatures:
|
|
28
|
+
Enabled: true
|
|
29
|
+
Exclude:
|
|
30
|
+
- lib/cli/kit/sorbet_runtime_stub.rb
|
|
31
|
+
- "test/**/*"
|
|
32
|
+
- bin/testunit
|
|
33
|
+
- "lib/cli/kit/support/test_helper.rb"
|
|
34
|
+
|
|
35
|
+
Sorbet/SignatureBuildOrder:
|
|
36
|
+
Enabled: true
|
|
37
|
+
|
|
38
|
+
Sorbet/KeywordArgumentOrdering:
|
|
39
|
+
Enabled: true
|
|
40
|
+
|
|
41
|
+
Sorbet/ConstantsFromStrings:
|
|
42
|
+
Enabled: true
|
|
43
|
+
Exclude:
|
|
44
|
+
- "examples/**/*"
|
|
45
|
+
|
|
46
|
+
Sorbet/ForbidIncludeConstLiteral:
|
|
47
|
+
Enabled: false
|
data/.rubocop.yml
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
inherit_gem:
|
|
2
|
+
rubocop-shopify: rubocop-cli.yml
|
|
3
|
+
|
|
1
4
|
inherit_from:
|
|
2
|
-
-
|
|
5
|
+
- .rubocop.sorbet.yml
|
|
6
|
+
|
|
7
|
+
require:
|
|
8
|
+
- rubocop-sorbet
|
|
3
9
|
|
|
4
10
|
AllCops:
|
|
5
|
-
Exclude:
|
|
6
|
-
|
|
11
|
+
Exclude:
|
|
12
|
+
- gen/template/**/*
|
|
13
|
+
- vendor/**/*
|
|
14
|
+
TargetRubyVersion: 2.7
|
|
15
|
+
NewCops: disable
|
|
7
16
|
|
|
8
17
|
Style/ClassAndModuleChildren:
|
|
9
18
|
Exclude:
|
|
@@ -12,15 +21,8 @@ Style/ClassAndModuleChildren:
|
|
|
12
21
|
Style/FrozenStringLiteralComment:
|
|
13
22
|
Enabled: false
|
|
14
23
|
|
|
15
|
-
Shopify/RubocopComments:
|
|
16
|
-
Enabled: false
|
|
17
|
-
|
|
18
|
-
# This doesn't understand that <<~ doesn't exist in 2.0
|
|
19
|
-
Layout/IndentHeredoc:
|
|
20
|
-
Enabled: false
|
|
21
|
-
|
|
22
24
|
# This doesn't take into account retrying from an exception
|
|
23
|
-
Lint/
|
|
25
|
+
Lint/SuppressedException:
|
|
24
26
|
Enabled: false
|
|
25
27
|
|
|
26
28
|
# allow String.new to create mutable strings
|
|
@@ -39,6 +41,13 @@ Style/RegexpLiteral:
|
|
|
39
41
|
Style/MultilineBlockChain:
|
|
40
42
|
Enabled: false
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
Style/StringLiterals:
|
|
45
|
+
EnforcedStyle: single_quotes
|
|
46
|
+
|
|
47
|
+
# We heavily manage output on purpose
|
|
48
|
+
Style/GlobalStdStream:
|
|
49
|
+
Enabled: false
|
|
50
|
+
|
|
51
|
+
# Sometimes (often) explicit is good
|
|
52
|
+
Style/EmptyElse:
|
|
44
53
|
Enabled: false
|
data/Gemfile
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
# NOTE: These are development-only dependencies
|
|
2
|
-
source
|
|
2
|
+
source 'https://rubygems.org'
|
|
3
3
|
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
6
|
group :development, :test do
|
|
7
|
-
gem '
|
|
7
|
+
gem 'cli-ui', git: 'https://github.com/Shopify/cli-ui', ref: '0eefd57248f42ec163639884e77a071d82bfbda8'
|
|
8
|
+
gem 'rubocop'
|
|
9
|
+
gem 'rubocop-rake'
|
|
10
|
+
gem 'rubocop-shopify'
|
|
11
|
+
gem 'rubocop-sorbet'
|
|
8
12
|
gem 'byebug'
|
|
9
13
|
gem 'method_source'
|
|
14
|
+
gem 'simplecov'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
group :typecheck do
|
|
18
|
+
gem 'sorbet-static-and-runtime'
|
|
19
|
+
gem 'tapioca', require: false
|
|
10
20
|
end
|
|
11
21
|
|
|
12
22
|
group :test do
|
|
13
|
-
gem 'mocha', '~>
|
|
23
|
+
gem 'mocha', '~> 2.0.1', require: false
|
|
14
24
|
gem 'minitest', '>= 5.0.0', require: false
|
|
15
25
|
gem 'minitest-reporters', require: false
|
|
16
26
|
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,56 +1,138 @@
|
|
|
1
|
+
GIT
|
|
2
|
+
remote: https://github.com/Shopify/cli-ui
|
|
3
|
+
revision: 0eefd57248f42ec163639884e77a071d82bfbda8
|
|
4
|
+
ref: 0eefd57248f42ec163639884e77a071d82bfbda8
|
|
5
|
+
specs:
|
|
6
|
+
cli-ui (1.5.1)
|
|
7
|
+
|
|
1
8
|
PATH
|
|
2
9
|
remote: .
|
|
3
10
|
specs:
|
|
4
|
-
cli-kit (
|
|
11
|
+
cli-kit (4.0.0)
|
|
5
12
|
cli-ui (>= 1.1.4)
|
|
6
13
|
|
|
7
14
|
GEM
|
|
8
15
|
remote: https://rubygems.org/
|
|
9
16
|
specs:
|
|
10
17
|
ansi (1.5.0)
|
|
11
|
-
ast (2.4.
|
|
12
|
-
builder (3.2.
|
|
13
|
-
byebug (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
minitest
|
|
18
|
+
ast (2.4.2)
|
|
19
|
+
builder (3.2.4)
|
|
20
|
+
byebug (11.1.3)
|
|
21
|
+
diff-lcs (1.5.0)
|
|
22
|
+
docile (1.4.0)
|
|
23
|
+
json (2.6.2)
|
|
24
|
+
method_source (1.0.0)
|
|
25
|
+
minitest (5.16.3)
|
|
26
|
+
minitest-reporters (1.5.0)
|
|
19
27
|
ansi
|
|
20
28
|
builder
|
|
21
29
|
minitest (>= 5.0)
|
|
22
30
|
ruby-progressbar
|
|
23
|
-
mocha (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
rainbow (3.
|
|
30
|
-
rake (
|
|
31
|
-
|
|
31
|
+
mocha (2.0.2)
|
|
32
|
+
ruby2_keywords (>= 0.0.5)
|
|
33
|
+
netrc (0.11.0)
|
|
34
|
+
parallel (1.22.1)
|
|
35
|
+
parser (3.1.2.1)
|
|
36
|
+
ast (~> 2.4.1)
|
|
37
|
+
rainbow (3.1.1)
|
|
38
|
+
rake (13.0.6)
|
|
39
|
+
rbi (0.0.16)
|
|
40
|
+
ast
|
|
41
|
+
parser (>= 2.6.4.0)
|
|
42
|
+
sorbet-runtime (>= 0.5.9204)
|
|
43
|
+
unparser
|
|
44
|
+
regexp_parser (2.6.0)
|
|
45
|
+
rexml (3.2.5)
|
|
46
|
+
rubocop (1.39.0)
|
|
47
|
+
json (~> 2.3)
|
|
32
48
|
parallel (~> 1.10)
|
|
33
|
-
parser (>= 2.
|
|
34
|
-
powerpack (~> 0.1)
|
|
49
|
+
parser (>= 3.1.2.1)
|
|
35
50
|
rainbow (>= 2.2.2, < 4.0)
|
|
51
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
52
|
+
rexml (>= 3.2.5, < 4.0)
|
|
53
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
|
36
54
|
ruby-progressbar (~> 1.7)
|
|
37
|
-
unicode-display_width (
|
|
38
|
-
|
|
39
|
-
|
|
55
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
56
|
+
rubocop-ast (1.23.0)
|
|
57
|
+
parser (>= 3.1.1.0)
|
|
58
|
+
rubocop-rake (0.6.0)
|
|
59
|
+
rubocop (~> 1.0)
|
|
60
|
+
rubocop-shopify (2.10.1)
|
|
61
|
+
rubocop (~> 1.35)
|
|
62
|
+
rubocop-sorbet (0.6.11)
|
|
63
|
+
rubocop (>= 0.90.0)
|
|
64
|
+
ruby-progressbar (1.11.0)
|
|
65
|
+
ruby2_keywords (0.0.5)
|
|
66
|
+
simplecov (0.21.2)
|
|
67
|
+
docile (~> 1.1)
|
|
68
|
+
simplecov-html (~> 0.11)
|
|
69
|
+
simplecov_json_formatter (~> 0.1)
|
|
70
|
+
simplecov-html (0.12.3)
|
|
71
|
+
simplecov_json_formatter (0.1.4)
|
|
72
|
+
sorbet (0.5.10554)
|
|
73
|
+
sorbet-static (= 0.5.10554)
|
|
74
|
+
sorbet-runtime (0.5.10554)
|
|
75
|
+
sorbet-static (0.5.10554-universal-darwin-14)
|
|
76
|
+
sorbet-static (0.5.10554-universal-darwin-15)
|
|
77
|
+
sorbet-static (0.5.10554-universal-darwin-16)
|
|
78
|
+
sorbet-static (0.5.10554-universal-darwin-17)
|
|
79
|
+
sorbet-static (0.5.10554-universal-darwin-18)
|
|
80
|
+
sorbet-static (0.5.10554-universal-darwin-19)
|
|
81
|
+
sorbet-static (0.5.10554-universal-darwin-20)
|
|
82
|
+
sorbet-static (0.5.10554-universal-darwin-21)
|
|
83
|
+
sorbet-static (0.5.10554-universal-darwin-22)
|
|
84
|
+
sorbet-static (0.5.10554-x86_64-linux)
|
|
85
|
+
sorbet-static-and-runtime (0.5.10554)
|
|
86
|
+
sorbet (= 0.5.10554)
|
|
87
|
+
sorbet-runtime (= 0.5.10554)
|
|
88
|
+
spoom (1.1.12)
|
|
89
|
+
sorbet (>= 0.5.9204)
|
|
90
|
+
sorbet-runtime (>= 0.5.9204)
|
|
91
|
+
thor (>= 0.19.2)
|
|
92
|
+
tapioca (0.10.3)
|
|
93
|
+
bundler (>= 1.17.3)
|
|
94
|
+
netrc (>= 0.11.0)
|
|
95
|
+
parallel (>= 1.21.0)
|
|
96
|
+
rbi (~> 0.0.0, >= 0.0.16)
|
|
97
|
+
sorbet-static-and-runtime (>= 0.5.9892)
|
|
98
|
+
spoom (~> 1.1.0, >= 1.1.11)
|
|
99
|
+
thor (>= 1.2.0)
|
|
100
|
+
yard-sorbet
|
|
101
|
+
thor (1.2.1)
|
|
102
|
+
unicode-display_width (2.3.0)
|
|
103
|
+
unparser (0.6.5)
|
|
104
|
+
diff-lcs (~> 1.3)
|
|
105
|
+
parser (>= 3.1.0)
|
|
106
|
+
webrick (1.7.0)
|
|
107
|
+
yard (0.9.28)
|
|
108
|
+
webrick (~> 1.7.0)
|
|
109
|
+
yard-sorbet (0.7.0)
|
|
110
|
+
sorbet-runtime (>= 0.5)
|
|
111
|
+
yard (>= 0.9)
|
|
40
112
|
|
|
41
113
|
PLATFORMS
|
|
114
|
+
arm64-darwin-21
|
|
42
115
|
ruby
|
|
116
|
+
universal-darwin
|
|
117
|
+
x86_64-linux
|
|
43
118
|
|
|
44
119
|
DEPENDENCIES
|
|
45
|
-
bundler (~> 1
|
|
120
|
+
bundler (~> 2.1)
|
|
46
121
|
byebug
|
|
47
122
|
cli-kit!
|
|
123
|
+
cli-ui!
|
|
48
124
|
method_source
|
|
49
125
|
minitest (>= 5.0.0)
|
|
50
126
|
minitest-reporters
|
|
51
|
-
mocha (~>
|
|
52
|
-
rake (~>
|
|
53
|
-
rubocop
|
|
127
|
+
mocha (~> 2.0.1)
|
|
128
|
+
rake (~> 13.0)
|
|
129
|
+
rubocop
|
|
130
|
+
rubocop-rake
|
|
131
|
+
rubocop-shopify
|
|
132
|
+
rubocop-sorbet
|
|
133
|
+
simplecov
|
|
134
|
+
sorbet-static-and-runtime
|
|
135
|
+
tapioca
|
|
54
136
|
|
|
55
137
|
BUNDLED WITH
|
|
56
|
-
|
|
138
|
+
2.2.24
|
data/README.md
CHANGED
|
@@ -26,9 +26,52 @@ select how the project consumes `cli-kit` and `cli-ui`. The available options a
|
|
|
26
26
|
|
|
27
27
|
You're now ready to write your very first `cli-kit` application!
|
|
28
28
|
|
|
29
|
+
## Upgrading to version 5
|
|
30
|
+
|
|
31
|
+
Version 5 includes breaking changes and significant new features. Notably:
|
|
32
|
+
|
|
33
|
+
* `autocall` is completely removed;
|
|
34
|
+
* A help system and command-line option parsing system is added.
|
|
35
|
+
|
|
36
|
+
Migrating away from `autocall` is as simple as replacing `autocall(:X) { y }` with `X = y`.
|
|
37
|
+
|
|
38
|
+
Using the new help system is not yet well-documented, but some hints can be found in the
|
|
39
|
+
`gen/ilb/gen/commands` directory of this repo. Existing commands in existing apps should continue to
|
|
40
|
+
work.
|
|
41
|
+
|
|
42
|
+
To use the new help system, commands should all define `invoke` instead of `call`. `invoke` takes
|
|
43
|
+
`name` as before, but the first argument is now an instance of `Opts`, defined in the command class,
|
|
44
|
+
which must be a subclass of `CLI::Kit::Opts`. For example:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
class MyCommand < CLI::Kit::BaseCommand
|
|
48
|
+
class Opts < CLI::Kit::Opts
|
|
49
|
+
def force
|
|
50
|
+
flag(short: '-f', long: '--force', description: 'Force the operation')
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
def invoke(op, _name)
|
|
54
|
+
if op.force
|
|
55
|
+
puts 'Forcing the operation'
|
|
56
|
+
else
|
|
57
|
+
puts 'Not forcing the operation'
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This particular structure was chosen to allow the code to by fully typed using sorbet, as `invoke`
|
|
64
|
+
can be tagged with `sig { params(op: Opts, _name: String).void }`, and the `#force` method visibly
|
|
65
|
+
exists.
|
|
66
|
+
|
|
67
|
+
`-h/--help` is installed as a default flag, and running this command with `--help` is handled before
|
|
68
|
+
reaching `#invoke`, to print a help message (for which several other class methods on `BaseCommand`
|
|
69
|
+
provide text: `command_name`, `desc`, `long_desc`, `usage`, `example`, and `help_sections`). See
|
|
70
|
+
`gen/lib/gen/commands/new.rb` for an example.
|
|
71
|
+
|
|
29
72
|
## How do `cli-kit` Applications Work?
|
|
30
73
|
|
|
31
|
-
The executable for your `cli-kit` app is stored in the "exe" directory.
|
|
74
|
+
The executable for your `cli-kit` app is stored in the "exe" directory. To execute the app, simply
|
|
32
75
|
run:
|
|
33
76
|
```bash
|
|
34
77
|
./exe/myproject
|
|
@@ -38,7 +81,7 @@ run:
|
|
|
38
81
|
* `/exe/` - Location of the executables for your application.
|
|
39
82
|
* `/lib/` - Location of the resources for your app (modules, classes, helpers, etc).
|
|
40
83
|
* `myproject.rb` - This file is the starting point for where to look for all other files. It
|
|
41
|
-
configures autoload
|
|
84
|
+
configures autoload for the app.
|
|
42
85
|
* `myproject/` - Stores the various commands/entry points.
|
|
43
86
|
* `entry_point.rb` - This is the file that is first called from the executable. It handles
|
|
44
87
|
loading and commands.
|
|
@@ -113,4 +156,4 @@ powerful command-line user interface elements. For more details on how to use `c
|
|
|
113
156
|
|
|
114
157
|
## Examples
|
|
115
158
|
|
|
116
|
-
- [A Simple To-Do App](https://github.com/Shopify/cli-kit-example)
|
|
159
|
+
- [A Simple To-Do App](https://github.com/Shopify/cli-kit-example)
|
data/Rakefile
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
|
2
|
+
require 'rake/testtask'
|
|
3
|
+
require 'rubocop/rake_task'
|
|
4
|
+
require 'bundler/gem_tasks'
|
|
5
|
+
require 'sorbet-runtime' unless ENV['BUNDLE_WITHOUT'] == 'typecheck'
|
|
6
|
+
|
|
7
|
+
TEST_ROOT = File.expand_path('../test', __FILE__)
|
|
8
|
+
|
|
9
|
+
Rake::TestTask.new do |t|
|
|
10
|
+
t.libs += ['test']
|
|
11
|
+
t.test_files = FileList[File.join(TEST_ROOT, '**', '*_test.rb')]
|
|
12
|
+
t.verbose = false
|
|
13
|
+
t.warning = false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
RuboCop::RakeTask.new(:style) do |t|
|
|
17
|
+
t.options = ['--display-cop-names']
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
task :test_gen_bundler do
|
|
21
|
+
sh 'DEPS=bundler bin/test_gen'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
task :test_gen_vendor do
|
|
25
|
+
sh 'DEPS=vendor bin/test_gen'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
task(default: [:test, :style, :test_gen_bundler, :test_gen_vendor])
|
data/bin/console
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'cli/kit'
|
|
5
5
|
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
|
@@ -10,5 +10,5 @@ require "cli/kit"
|
|
|
10
10
|
# require "pry"
|
|
11
11
|
# Pry.start
|
|
12
12
|
|
|
13
|
-
require
|
|
13
|
+
require 'irb'
|
|
14
14
|
IRB.start(__FILE__)
|
data/bin/onchange
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# typed: ignore
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
|
|
5
|
+
require('open3')
|
|
6
|
+
|
|
7
|
+
extra_fswatch_args, cmd_args = if (rest_index = ARGV.index('--'))
|
|
8
|
+
[ARGV[0...rest_index], ARGV[rest_index + 1..-1]]
|
|
9
|
+
else
|
|
10
|
+
[[], ARGV]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
if cmd_args.size == 1 && cmd_args =~ /[&;|]/
|
|
14
|
+
cmd_args = ['bash', '-c', cmd_args[0]]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
system(*cmd_args)
|
|
18
|
+
|
|
19
|
+
fswatch_args = [
|
|
20
|
+
'-e', 'coverage',
|
|
21
|
+
'-e', '/\.git',
|
|
22
|
+
'--one-per-batch',
|
|
23
|
+
*extra_fswatch_args,
|
|
24
|
+
'.',
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
Open3.popen3('fswatch', *fswatch_args) do |stdin, stdout, _stderr, _wait_thr|
|
|
28
|
+
stdin.close
|
|
29
|
+
stdout.each { |_| system(*cmd_args) }
|
|
30
|
+
end
|
data/bin/tapioca
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'tapioca' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require 'pathname'
|
|
12
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
|
13
|
+
Pathname.new(__FILE__).realpath)
|
|
14
|
+
|
|
15
|
+
bundle_binstub = File.expand_path('../bundle', __FILE__)
|
|
16
|
+
|
|
17
|
+
if File.file?(bundle_binstub)
|
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
19
|
+
load(bundle_binstub)
|
|
20
|
+
else
|
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require 'rubygems'
|
|
27
|
+
require 'bundler/setup'
|
|
28
|
+
|
|
29
|
+
load Gem.bin_path('tapioca', 'tapioca')
|
data/bin/test_gen
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
2
3
|
|
|
3
4
|
# Make sure we're in the cli kit directory
|
|
4
5
|
CURR_DIR=$(dirname "$0")
|
|
@@ -19,7 +20,9 @@ mv myapp ../
|
|
|
19
20
|
cd ../myapp
|
|
20
21
|
|
|
21
22
|
# Test
|
|
22
|
-
|
|
23
|
+
if [[ $DEPS == 'bundler' ]]; then
|
|
24
|
+
bundle install
|
|
25
|
+
fi
|
|
23
26
|
bin/testunit
|
|
24
27
|
|
|
25
28
|
if [[ $DEPS == 'vendor' ]]; then
|
data/bin/testunit
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'rubygems'
|
|
4
4
|
require 'bundler/setup'
|
|
5
|
+
require 'sorbet-runtime' unless ENV['BUNDLE_WITHOUT'] == 'typecheck'
|
|
5
6
|
|
|
6
7
|
root = File.expand_path('../..', __FILE__)
|
|
7
8
|
CLI_TEST_ROOT = root + '/test'
|
|
@@ -9,12 +10,12 @@ CLI_TEST_ROOT = root + '/test'
|
|
|
9
10
|
$LOAD_PATH.unshift(CLI_TEST_ROOT)
|
|
10
11
|
|
|
11
12
|
def test_files
|
|
12
|
-
Dir.glob(CLI_TEST_ROOT +
|
|
13
|
+
Dir.glob(CLI_TEST_ROOT + '/**/*_test.rb')
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
if ARGV.empty?
|
|
16
17
|
test_files.each { |f| require(f) }
|
|
17
|
-
exit
|
|
18
|
+
exit(0)
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
# A list of files is presumed to be specified
|
data/cli-kit.gemspec
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
|
+
|
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
5
|
require 'cli/kit/version'
|
|
@@ -14,16 +15,16 @@ Gem::Specification.new do |spec|
|
|
|
14
15
|
spec.homepage = 'https://github.com/shopify/cli-kit'
|
|
15
16
|
spec.license = 'MIT'
|
|
16
17
|
|
|
17
|
-
spec.files =
|
|
18
|
-
f.match(%r{^(test|spec|features)/})
|
|
18
|
+
spec.files = %x(git ls-files -z).split("\x0").reject do |f|
|
|
19
|
+
f.match(%r{^(sorbet|test|spec|features)/})
|
|
19
20
|
end
|
|
20
21
|
spec.bindir = 'exe'
|
|
21
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
23
|
spec.require_paths = ['lib']
|
|
23
24
|
|
|
24
|
-
spec.add_runtime_dependency
|
|
25
|
+
spec.add_runtime_dependency('cli-ui', '~> 2.0')
|
|
25
26
|
|
|
26
|
-
spec.add_development_dependency
|
|
27
|
-
spec.add_development_dependency
|
|
28
|
-
spec.add_development_dependency
|
|
27
|
+
spec.add_development_dependency('bundler', '~> 2.1')
|
|
28
|
+
spec.add_development_dependency('minitest', '~> 5.0')
|
|
29
|
+
spec.add_development_dependency('rake', '~> 13.0')
|
|
29
30
|
end
|