rfix 1.4.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/rfix +78 -34
- data/lib/rfix.rb +17 -28
- data/lib/rfix/branch.rb +3 -25
- data/lib/rfix/branch/base.rb +27 -0
- data/lib/rfix/branch/head.rb +15 -0
- data/lib/rfix/branch/main.rb +33 -0
- data/lib/rfix/branch/name.rb +21 -0
- data/lib/rfix/branch/reference.rb +15 -0
- data/lib/rfix/branch/upstream.rb +17 -0
- data/lib/rfix/cli/command.rb +19 -0
- data/lib/rfix/cli/command/base.rb +61 -0
- data/lib/rfix/cli/command/branch.rb +13 -0
- data/lib/rfix/cli/command/config.rb +22 -0
- data/lib/rfix/cli/command/extension.rb +25 -0
- data/lib/rfix/cli/command/help.rb +11 -0
- data/lib/rfix/cli/command/info.rb +11 -0
- data/lib/rfix/cli/command/lint.rb +17 -0
- data/lib/rfix/cli/command/local.rb +11 -0
- data/lib/rfix/cli/command/origin.rb +11 -0
- data/lib/rfix/cli/command/setup.rb +11 -0
- data/lib/rfix/error.rb +5 -1
- data/lib/rfix/extension/offense.rb +79 -0
- data/lib/rfix/extension/pastel.rb +11 -0
- data/lib/rfix/extension/string.rb +12 -0
- data/lib/rfix/extension/strings.rb +9 -0
- data/lib/rfix/file.rb +6 -41
- data/lib/rfix/file/base.rb +73 -0
- data/lib/rfix/file/deleted.rb +17 -0
- data/lib/rfix/file/ignored.rb +17 -0
- data/lib/rfix/file/tracked.rb +42 -0
- data/lib/rfix/file/untracked.rb +20 -0
- data/lib/rfix/formatter.rb +125 -86
- data/lib/rfix/highlighter.rb +118 -0
- data/lib/rfix/indicator.rb +19 -0
- data/lib/rfix/log.rb +12 -121
- data/lib/rfix/rake/gemfile.rb +111 -0
- data/lib/rfix/rake/paths.rb +25 -23
- data/lib/rfix/rake/support.rb +72 -57
- data/lib/rfix/repository.rb +114 -164
- data/lib/rfix/types.rb +52 -0
- data/lib/rfix/version.rb +1 -1
- data/rfix.gemspec +28 -38
- data/vendor/dry-cli/CHANGELOG.md +191 -0
- data/vendor/dry-cli/CODEOWNERS +1 -0
- data/vendor/dry-cli/CODE_OF_CONDUCT.md +13 -0
- data/vendor/dry-cli/CONTRIBUTING.md +29 -0
- data/vendor/dry-cli/Gemfile +14 -0
- data/vendor/dry-cli/Gemfile.devtools +18 -0
- data/vendor/dry-cli/LICENSE +20 -0
- data/vendor/dry-cli/README.md +29 -0
- data/vendor/dry-cli/Rakefile +13 -0
- data/vendor/dry-cli/bin/console +15 -0
- data/vendor/dry-cli/bin/setup +8 -0
- data/vendor/dry-cli/changelog.yml +97 -0
- data/vendor/dry-cli/docsite/source/arguments.html.md +57 -0
- data/vendor/dry-cli/docsite/source/callbacks.html.md +51 -0
- data/vendor/dry-cli/docsite/source/commands-with-subcommands-and-params.md +86 -0
- data/vendor/dry-cli/docsite/source/commands.html.md +41 -0
- data/vendor/dry-cli/docsite/source/index.html.md +302 -0
- data/vendor/dry-cli/docsite/source/options.html.md +51 -0
- data/vendor/dry-cli/docsite/source/subcommands.html.md +38 -0
- data/vendor/dry-cli/docsite/source/variadic-arguments.html.md +45 -0
- data/vendor/dry-cli/dry-cli.gemspec +36 -0
- data/vendor/dry-cli/lib/dry/cli.rb +224 -0
- data/vendor/dry-cli/lib/dry/cli/banner.rb +135 -0
- data/vendor/dry-cli/lib/dry/cli/command.rb +387 -0
- data/vendor/dry-cli/lib/dry/cli/command_registry.rb +253 -0
- data/vendor/dry-cli/lib/dry/cli/errors.rb +37 -0
- data/vendor/dry-cli/lib/dry/cli/inflector.rb +17 -0
- data/vendor/dry-cli/lib/dry/cli/inline.rb +75 -0
- data/vendor/dry-cli/lib/dry/cli/option.rb +131 -0
- data/vendor/dry-cli/lib/dry/cli/parser.rb +138 -0
- data/vendor/dry-cli/lib/dry/cli/program_name.rb +21 -0
- data/vendor/dry-cli/lib/dry/cli/registry.rb +338 -0
- data/vendor/dry-cli/lib/dry/cli/usage.rb +94 -0
- data/vendor/dry-cli/lib/dry/cli/version.rb +8 -0
- data/vendor/dry-cli/project.yml +13 -0
- data/vendor/dry-cli/spec/integration/commands_spec.rb +14 -0
- data/vendor/dry-cli/spec/integration/inherited_commands_spec.rb +24 -0
- data/vendor/dry-cli/spec/integration/inline_spec.rb +43 -0
- data/vendor/dry-cli/spec/integration/processes_errors_spec.rb +29 -0
- data/vendor/dry-cli/spec/integration/rendering_spec.rb +31 -0
- data/vendor/dry-cli/spec/integration/single_command_spec.rb +81 -0
- data/vendor/dry-cli/spec/integration/subcommands_spec.rb +60 -0
- data/vendor/dry-cli/spec/integration/third_party_gems_spec.rb +18 -0
- data/vendor/dry-cli/spec/spec_helper.rb +15 -0
- data/vendor/dry-cli/spec/support/coverage.rb +15 -0
- data/vendor/dry-cli/spec/support/files.rb +13 -0
- data/vendor/dry-cli/spec/support/fixtures/based +65 -0
- data/vendor/dry-cli/spec/support/fixtures/baz +9 -0
- data/vendor/dry-cli/spec/support/fixtures/baz_command.rb +19 -0
- data/vendor/dry-cli/spec/support/fixtures/foo +588 -0
- data/vendor/dry-cli/spec/support/fixtures/infinites +31 -0
- data/vendor/dry-cli/spec/support/fixtures/inline +20 -0
- data/vendor/dry-cli/spec/support/fixtures/registry.rb +15 -0
- data/vendor/dry-cli/spec/support/fixtures/shared_commands.rb +596 -0
- data/vendor/dry-cli/spec/support/fixtures/with_block.rb +86 -0
- data/vendor/dry-cli/spec/support/fixtures/with_registry.rb +90 -0
- data/vendor/dry-cli/spec/support/fixtures/with_zero_arity_block.rb +87 -0
- data/vendor/dry-cli/spec/support/helpers.rb +37 -0
- data/vendor/dry-cli/spec/support/path.rb +24 -0
- data/vendor/dry-cli/spec/support/rspec.rb +26 -0
- data/vendor/dry-cli/spec/support/rspec_options.rb +16 -0
- data/vendor/dry-cli/spec/support/shared_examples/commands.rb +300 -0
- data/vendor/dry-cli/spec/support/shared_examples/inherited_commands.rb +197 -0
- data/vendor/dry-cli/spec/support/shared_examples/rendering.rb +181 -0
- data/vendor/dry-cli/spec/support/shared_examples/subcommands.rb +226 -0
- data/vendor/dry-cli/spec/support/shared_examples/third_party_gems.rb +49 -0
- data/vendor/dry-cli/spec/support/warnings.rb +10 -0
- data/vendor/dry-cli/spec/unit/dry/cli/cli_spec.rb +123 -0
- data/vendor/dry-cli/spec/unit/dry/cli/inflector_spec.rb +26 -0
- data/vendor/dry-cli/spec/unit/dry/cli/registry_spec.rb +78 -0
- data/vendor/dry-cli/spec/unit/dry/cli/version_spec.rb +7 -0
- data/vendor/strings-ansi/CHANGELOG.md +24 -0
- data/vendor/strings-ansi/CODE_OF_CONDUCT.md +74 -0
- data/vendor/strings-ansi/Gemfile +11 -0
- data/{LICENSE.txt → vendor/strings-ansi/LICENSE.txt} +1 -1
- data/vendor/strings-ansi/README.md +155 -0
- data/vendor/strings-ansi/Rakefile +8 -0
- data/vendor/strings-ansi/appveyor.yml +32 -0
- data/vendor/strings-ansi/bin/console +14 -0
- data/vendor/strings-ansi/bin/setup +8 -0
- data/vendor/strings-ansi/lib/strings-ansi.rb +1 -0
- data/vendor/strings-ansi/lib/strings/ansi.rb +84 -0
- data/vendor/strings-ansi/lib/strings/ansi/extensions.rb +23 -0
- data/vendor/strings-ansi/lib/strings/ansi/version.rb +7 -0
- data/vendor/strings-ansi/spec/fixtures/ansi_codes.yaml +194 -0
- data/vendor/strings-ansi/spec/spec_helper.rb +51 -0
- data/vendor/strings-ansi/spec/unit/ansi_spec.rb +15 -0
- data/vendor/strings-ansi/spec/unit/extensions_spec.rb +19 -0
- data/vendor/strings-ansi/spec/unit/only_ansi_spec.rb +36 -0
- data/vendor/strings-ansi/spec/unit/sanitize_spec.rb +53 -0
- data/vendor/strings-ansi/strings-ansi.gemspec +34 -0
- data/vendor/strings-ansi/tasks/console.rake +11 -0
- data/vendor/strings-ansi/tasks/coverage.rake +11 -0
- data/vendor/strings-ansi/tasks/spec.rake +29 -0
- metadata +274 -188
- data/.github/workflows/main.yml +0 -26
- data/.gitignore +0 -43
- data/.rspec +0 -2
- data/.rubocop.yml +0 -87
- data/.travis.yml +0 -35
- data/Gemfile +0 -2
- data/Gemfile.base +0 -14
- data/Gemfile.base.lock +0 -172
- data/Gemfile.lock +0 -188
- data/Guardfile +0 -16
- data/Makefile +0 -12
- data/README.md +0 -85
- data/Rakefile +0 -31
- data/bin/bundle +0 -114
- data/bin/console +0 -29
- data/bin/guard +0 -29
- data/bin/rake +0 -29
- data/bin/rfix +0 -29
- data/bin/rspec +0 -29
- data/bin/setup +0 -29
- data/ci/Gemfile.rubocop-0.80 +0 -2
- data/ci/Gemfile.rubocop-0.80.lock +0 -170
- data/ci/Gemfile.rubocop-0.81 +0 -2
- data/ci/Gemfile.rubocop-0.81.lock +0 -170
- data/ci/Gemfile.rubocop-0.82 +0 -2
- data/ci/Gemfile.rubocop-0.82.lock +0 -170
- data/ci/Gemfile.rubocop-0.83 +0 -2
- data/ci/Gemfile.rubocop-0.83.lock +0 -168
- data/ci/Gemfile.rubocop-0.84 +0 -2
- data/ci/Gemfile.rubocop-0.84.lock +0 -171
- data/ci/Gemfile.rubocop-0.85 +0 -2
- data/ci/Gemfile.rubocop-0.85.1 +0 -2
- data/ci/Gemfile.rubocop-0.85.1.lock +0 -173
- data/ci/Gemfile.rubocop-0.85.lock +0 -173
- data/lib/rfix/box.rb +0 -112
- data/lib/rfix/branches/base.rb +0 -15
- data/lib/rfix/branches/head.rb +0 -13
- data/lib/rfix/branches/main.rb +0 -28
- data/lib/rfix/branches/name.rb +0 -23
- data/lib/rfix/branches/reference.rb +0 -21
- data/lib/rfix/branches/upstream.rb +0 -13
- data/lib/rfix/cmd.rb +0 -39
- data/lib/rfix/commands/branch.rb +0 -15
- data/lib/rfix/commands/extensions/options.rb +0 -8
- data/lib/rfix/commands/help.rb +0 -7
- data/lib/rfix/commands/helper/args.rb +0 -141
- data/lib/rfix/commands/helper/help.rb +0 -6
- data/lib/rfix/commands/helper/loader.rb +0 -6
- data/lib/rfix/commands/helper/option.rb +0 -0
- data/lib/rfix/commands/helper/params.rb +0 -0
- data/lib/rfix/commands/helper/rubocop.rb +0 -17
- data/lib/rfix/commands/info.rb +0 -30
- data/lib/rfix/commands/lint.rb +0 -22
- data/lib/rfix/commands/local.rb +0 -12
- data/lib/rfix/commands/origin.rb +0 -19
- data/lib/rfix/commands/setup.rb +0 -29
- data/lib/rfix/commands/welcome.rb +0 -24
- data/lib/rfix/deleted.rb +0 -13
- data/lib/rfix/extensions/extensions.rb +0 -18
- data/lib/rfix/extensions/offense.rb +0 -78
- data/lib/rfix/extensions/string.rb +0 -8
- data/lib/rfix/file_cache.rb +0 -59
- data/lib/rfix/git_helper.rb +0 -59
- data/lib/rfix/indentation.rb +0 -39
- data/lib/rfix/loader/bundler.rb +0 -37
- data/lib/rfix/loader/env.rb +0 -33
- data/lib/rfix/loader/spec.rb +0 -41
- data/lib/rfix/no_file.rb +0 -13
- data/lib/rfix/rfix.rb +0 -34
- data/lib/rfix/tracked.rb +0 -72
- data/lib/rfix/tracked_file.rb +0 -16
- data/lib/rfix/untracked.rb +0 -13
- data/resources/ps.png +0 -0
- data/tasks/bump.rake +0 -11
- data/tasks/bundle.rake +0 -17
- data/tasks/complex.rake +0 -54
- data/tasks/execute.rake +0 -38
- data/tasks/libgit2.rake +0 -33
- data/tasks/simple.rake +0 -62
- data/tasks/travis.rake +0 -74
- data/tasks/vendor.rake +0 -34
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/cli/program_name"
|
4
|
+
|
5
|
+
module Dry
|
6
|
+
class CLI
|
7
|
+
# Command(s) usage
|
8
|
+
#
|
9
|
+
# @since 0.1.0
|
10
|
+
# @api private
|
11
|
+
module Usage
|
12
|
+
# @since 0.1.0
|
13
|
+
# @api private
|
14
|
+
SUBCOMMAND_BANNER = " [SUBCOMMAND]"
|
15
|
+
ROOT_COMMAND_WITH_SUBCOMMANDS_BANNER = " [ARGUMENT|SUBCOMMAND]"
|
16
|
+
|
17
|
+
# @since 0.1.0
|
18
|
+
# @api private
|
19
|
+
def self.call(result)
|
20
|
+
header = "Commands:"
|
21
|
+
max_length, commands = commands_and_arguments(result)
|
22
|
+
|
23
|
+
commands.map do |banner, node|
|
24
|
+
usage = description(node.command) if node.leaf?
|
25
|
+
"#{justify(banner, max_length, usage)}#{usage}"
|
26
|
+
end.unshift(header).join("\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
# @since 0.1.0
|
30
|
+
# @api private
|
31
|
+
def self.commands_and_arguments(result)
|
32
|
+
max_length = 0
|
33
|
+
ret = commands(result).each_with_object({}) do |(name, node), memo|
|
34
|
+
args = if node.command && node.leaf? && node.children?
|
35
|
+
ROOT_COMMAND_WITH_SUBCOMMANDS_BANNER
|
36
|
+
elsif node.leaf?
|
37
|
+
arguments(node.command)
|
38
|
+
else
|
39
|
+
SUBCOMMAND_BANNER
|
40
|
+
end
|
41
|
+
|
42
|
+
partial = " #{command_name(result, name)}#{args}"
|
43
|
+
max_length = partial.bytesize if max_length < partial.bytesize
|
44
|
+
memo[partial] = node
|
45
|
+
end
|
46
|
+
|
47
|
+
[max_length, ret]
|
48
|
+
end
|
49
|
+
|
50
|
+
# @since 0.1.0
|
51
|
+
# @api private
|
52
|
+
def self.arguments(command)
|
53
|
+
return unless CLI.command?(command)
|
54
|
+
|
55
|
+
required_arguments = command.required_arguments
|
56
|
+
optional_arguments = command.optional_arguments
|
57
|
+
|
58
|
+
required = required_arguments.map { |arg| arg.name.upcase }.join(" ") if required_arguments.any? # rubocop:disable Metrics/LineLength
|
59
|
+
optional = optional_arguments.map { |arg| "[#{arg.name.upcase}]" }.join(" ") if optional_arguments.any? # rubocop:disable Metrics/LineLength
|
60
|
+
result = [required, optional].compact
|
61
|
+
|
62
|
+
" #{result.join(" ")}" unless result.empty?
|
63
|
+
end
|
64
|
+
|
65
|
+
# @since 0.1.0
|
66
|
+
# @api private
|
67
|
+
def self.description(command)
|
68
|
+
return unless CLI.command?(command)
|
69
|
+
|
70
|
+
" # #{command.description}" unless command.description.nil?
|
71
|
+
end
|
72
|
+
|
73
|
+
# @since 0.1.0
|
74
|
+
# @api private
|
75
|
+
def self.justify(string, padding, usage)
|
76
|
+
return string.chomp(" ") if usage.nil?
|
77
|
+
|
78
|
+
string.ljust(padding + padding / 2)
|
79
|
+
end
|
80
|
+
|
81
|
+
# @since 0.1.0
|
82
|
+
# @api private
|
83
|
+
def self.commands(result)
|
84
|
+
result.children.sort_by { |name, _| name }
|
85
|
+
end
|
86
|
+
|
87
|
+
# @since 0.1.0
|
88
|
+
# @api private
|
89
|
+
def self.command_name(result, name)
|
90
|
+
ProgramName.call([result.names, name])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
name: dry-cli
|
2
|
+
codacy_id: 61dd5d070fc74f0cacf575b19d4930e1
|
3
|
+
gemspec:
|
4
|
+
authors: ["Luca Guidi"]
|
5
|
+
email: ["me@lucaguidi.com"]
|
6
|
+
summary: "Common framework to build command line interfaces with Ruby"
|
7
|
+
required_ruby_version: ">= 2.4.0"
|
8
|
+
development_dependencies:
|
9
|
+
- [bundler, ">= 1.6", "< 3"]
|
10
|
+
- [rake, "~> 13.0"]
|
11
|
+
- [rspec, "~> 3.7"]
|
12
|
+
- [simplecov, "~> 0.17.1"]
|
13
|
+
- [rubocop, "~> 0.82"]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "Commands" do
|
4
|
+
context "with extra params" do
|
5
|
+
context "when there is a required argument" do
|
6
|
+
context "and there are options" do
|
7
|
+
it "parses both separately" do
|
8
|
+
output = `foo variadic with-mandatory-and-options uno -- due tre --blah`
|
9
|
+
expect(output).to eq("first: uno\nurl: \nmethod: \nUnused Arguments: due, tre, --blah\n")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "Inherited commands" do
|
4
|
+
context "when --help flag" do
|
5
|
+
it "subclass do not" do
|
6
|
+
output = `based --help 2>&1`
|
7
|
+
expected = <<~OUT
|
8
|
+
Commands:
|
9
|
+
based addons APP # Lists your add-ons and attachments
|
10
|
+
based logs APP # Display recent log output
|
11
|
+
based run APP CMD # Run a one-off process inside your app
|
12
|
+
based subrun APP CMD
|
13
|
+
OUT
|
14
|
+
expect(output).to eq(expected)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "works for subclasses" do
|
19
|
+
output = `based subrun application_name command_to_run`
|
20
|
+
expect(output).to eq(
|
21
|
+
"Run - App: application_name - Command: command_to_run - Options: {:verbosity=>\"INFO\"}\n"
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
|
5
|
+
RSpec.describe "Inline" do
|
6
|
+
context "with command" do
|
7
|
+
let(:cmd) { "inline" }
|
8
|
+
|
9
|
+
it "shows help" do
|
10
|
+
output = `inline -h`
|
11
|
+
expected_output = <<~OUTPUT
|
12
|
+
Command:
|
13
|
+
inline
|
14
|
+
|
15
|
+
Usage:
|
16
|
+
inline MANDATORY_ARG [OPTIONAL_ARG]
|
17
|
+
|
18
|
+
Description:
|
19
|
+
Baz command line interface
|
20
|
+
|
21
|
+
Arguments:
|
22
|
+
MANDATORY_ARG # REQUIRED Mandatory argument
|
23
|
+
OPTIONAL_ARG # Optional argument (has to have default value in call method)
|
24
|
+
|
25
|
+
Options:
|
26
|
+
--option-one=VALUE, -1 VALUE # Option one
|
27
|
+
--[no-]boolean-option, -b # Option boolean
|
28
|
+
--option-with-default=VALUE, -d VALUE # Option default, default: "test"
|
29
|
+
--help, -h # Print this help
|
30
|
+
OUTPUT
|
31
|
+
expect(output).to eq(expected_output)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "with underscored option_one" do
|
35
|
+
output = `inline first_arg -1 test2 -bd test3`
|
36
|
+
expect(output).to eq(
|
37
|
+
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
|
38
|
+
'Options: {:option_with_default=>"test3", :option_one=>"test2", :boolean_option=>true}' \
|
39
|
+
"\n"
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "Processes Errors" do
|
4
|
+
context "when SignalException" do
|
5
|
+
it "returns correct statuscode" do
|
6
|
+
pid1, pid2, pid15 = Array.new(3).map { Process.spawn("foo generate app SomeAppName") }
|
7
|
+
sleep 0.5 # time to start app
|
8
|
+
|
9
|
+
Process.kill("HUP", pid1)
|
10
|
+
Process.kill("INT", pid2)
|
11
|
+
Process.kill("TERM", pid15)
|
12
|
+
|
13
|
+
_, status1 = Process.wait2(pid1)
|
14
|
+
_, status2 = Process.wait2(pid2)
|
15
|
+
_, status15 = Process.wait2(pid15)
|
16
|
+
|
17
|
+
expect(status1.exitstatus).to eq(129)
|
18
|
+
expect(status2.exitstatus).to eq(130)
|
19
|
+
expect(status15.exitstatus).to eq(143)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when Pipe Exception" do
|
24
|
+
it "handles EPIPE without stacktrace" do
|
25
|
+
output = `infinites writer | head -n 3`
|
26
|
+
expect(output).to eq("0\n1\n2\n")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
|
5
|
+
RSpec.describe "Rendering" do
|
6
|
+
it "prints available commands for unknown command" do
|
7
|
+
_, stderr, = Open3.capture3("foo unknown")
|
8
|
+
|
9
|
+
expected = <<~DESC
|
10
|
+
Commands:
|
11
|
+
foo assets [SUBCOMMAND]
|
12
|
+
foo callbacks DIR # Command with callbacks
|
13
|
+
foo console # Starts Foo console
|
14
|
+
foo db [SUBCOMMAND]
|
15
|
+
foo destroy [SUBCOMMAND]
|
16
|
+
foo exec TASK [DIRS] # Execute a task
|
17
|
+
foo generate [SUBCOMMAND]
|
18
|
+
foo greeting [RESPONSE]
|
19
|
+
foo hello # Print a greeting
|
20
|
+
foo new PROJECT # Generate a new Foo project
|
21
|
+
foo root-command [ARGUMENT|SUBCOMMAND] # Root command with arguments and subcommands
|
22
|
+
foo routes # Print routes
|
23
|
+
foo server # Start Foo server (only for development)
|
24
|
+
foo sub [SUBCOMMAND]
|
25
|
+
foo variadic [SUBCOMMAND]
|
26
|
+
foo version # Print Foo version
|
27
|
+
DESC
|
28
|
+
|
29
|
+
expect(stderr).to eq(expected)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
|
5
|
+
RSpec.describe "Single command" do
|
6
|
+
context "with command" do
|
7
|
+
let(:cmd) { "baz" }
|
8
|
+
|
9
|
+
it "shows usage" do
|
10
|
+
_, stderr, = Open3.capture3("baz")
|
11
|
+
expect(stderr).to eq(
|
12
|
+
"ERROR: \"#{cmd}\" was called with no arguments\nUsage: \"#{cmd} MANDATORY_ARG\"\n"
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "shows help" do
|
17
|
+
output = `baz -h`
|
18
|
+
expected_output = <<~OUTPUT
|
19
|
+
Command:
|
20
|
+
#{cmd}
|
21
|
+
|
22
|
+
Usage:
|
23
|
+
#{cmd} MANDATORY_ARG [OPTIONAL_ARG]
|
24
|
+
|
25
|
+
Description:
|
26
|
+
Baz command line interface
|
27
|
+
|
28
|
+
Arguments:
|
29
|
+
MANDATORY_ARG # REQUIRED Mandatory argument
|
30
|
+
OPTIONAL_ARG # Optional argument (has to have default value in call method)
|
31
|
+
|
32
|
+
Options:
|
33
|
+
--option-one=VALUE, -1 VALUE # Option one
|
34
|
+
--[no-]boolean-option, -b # Option boolean
|
35
|
+
--option-with-default=VALUE, -d VALUE # Option default, default: "test"
|
36
|
+
--help, -h # Print this help
|
37
|
+
OUTPUT
|
38
|
+
expect(output).to eq(expected_output)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "with option_one" do
|
42
|
+
output = `baz first_arg --option-one=test2`
|
43
|
+
expect(output).to eq(
|
44
|
+
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
|
45
|
+
"Options: {:option_with_default=>\"test\", :option_one=>\"test2\"}\n"
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "with combination of aliases" do
|
50
|
+
output = `baz first_arg -bd test3`
|
51
|
+
expect(output).to eq(
|
52
|
+
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
|
53
|
+
"Options: {:option_with_default=>\"test3\", :boolean_option=>true}\n"
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "root command with arguments and subcommands" do
|
59
|
+
it "with arguments" do
|
60
|
+
output = `foo root-command "hello world"`
|
61
|
+
|
62
|
+
expected = <<~DESC
|
63
|
+
I'm a root-command argument:hello world
|
64
|
+
I'm a root-command option:
|
65
|
+
DESC
|
66
|
+
|
67
|
+
expect(output).to eq(expected)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "with options" do
|
71
|
+
output = `foo root-command "hello world" --root-command-option="bye world"`
|
72
|
+
|
73
|
+
expected = <<~DESC
|
74
|
+
I'm a root-command argument:hello world
|
75
|
+
I'm a root-command option:bye world
|
76
|
+
DESC
|
77
|
+
|
78
|
+
expect(output).to eq(expected)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
|
5
|
+
RSpec.describe "Subcommands" do
|
6
|
+
context "works with params" do
|
7
|
+
it "with help param" do
|
8
|
+
output = `foo generate model --help`
|
9
|
+
|
10
|
+
expected = <<~DESC
|
11
|
+
Command:
|
12
|
+
foo generate model
|
13
|
+
|
14
|
+
Usage:
|
15
|
+
foo generate model MODEL
|
16
|
+
|
17
|
+
Description:
|
18
|
+
Generate a model
|
19
|
+
|
20
|
+
Arguments:
|
21
|
+
MODEL # REQUIRED Model name (eg. `user`)
|
22
|
+
|
23
|
+
Options:
|
24
|
+
--[no-]skip-migration # Skip migration, default: false
|
25
|
+
--help, -h # Print this help
|
26
|
+
|
27
|
+
Examples:
|
28
|
+
foo generate model user # Generate `User` entity, `UserRepository` repository, and the migration
|
29
|
+
foo generate model user --skip-migration # Generate `User` entity and `UserRepository` repository
|
30
|
+
DESC
|
31
|
+
|
32
|
+
expect(output).to eq(expected)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "works with root command subcommands" do
|
37
|
+
it "with params" do
|
38
|
+
output = `foo root-command sub-command "hello world"`
|
39
|
+
|
40
|
+
expected = <<~DESC
|
41
|
+
I'm a root-command sub-command argument:hello world
|
42
|
+
I'm a root-command sub-command option:
|
43
|
+
DESC
|
44
|
+
|
45
|
+
expect(output).to eq(expected)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "with options" do
|
49
|
+
option = '--root-command-sub-command-option="bye world"'
|
50
|
+
output = `foo root-command sub-command "hello world" #{option}`
|
51
|
+
|
52
|
+
expected = <<~DESC
|
53
|
+
I'm a root-command sub-command argument:hello world
|
54
|
+
I'm a root-command sub-command option:bye world
|
55
|
+
DESC
|
56
|
+
|
57
|
+
expect(output).to eq(expected)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "Third-party gems" do
|
4
|
+
it "allows to add callbacks as a block" do
|
5
|
+
output = `foo callbacks . --url=https://hanamirb.test`
|
6
|
+
|
7
|
+
expected = <<~OUTPUT
|
8
|
+
before command callback Foo::Webpack::CLI::CallbacksCommand {:url=>"https://hanamirb.test", :dir=>"."}
|
9
|
+
before callback (class), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
|
10
|
+
before callback (object), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
|
11
|
+
dir: ., url: "https://hanamirb.test"
|
12
|
+
after command callback Foo::Webpack::CLI::CallbacksCommand {:url=>"https://hanamirb.test", :dir=>"."}
|
13
|
+
after callback (class), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
|
14
|
+
after callback (object), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
|
15
|
+
OUTPUT
|
16
|
+
expect(output).to eq(expected)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "support/coverage"
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift "lib"
|
6
|
+
require "dry/cli"
|
7
|
+
require_relative "./support/rspec"
|
8
|
+
|
9
|
+
%w[support].each do |dir|
|
10
|
+
Dir[File.join(Dir.pwd, "spec", dir, "**", "*.rb")].each do |file|
|
11
|
+
unless file["support/warnings.rb"]
|
12
|
+
require_relative file
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|