rfix 1.4.1 → 2.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/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,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.shared_examples "Third-party gems" do |cli|
|
|
4
|
+
let(:cli) { cli }
|
|
5
|
+
|
|
6
|
+
let(:cmd) { File.basename($PROGRAM_NAME, File.extname($PROGRAM_NAME)) }
|
|
7
|
+
|
|
8
|
+
it "allows to add a subcommand" do
|
|
9
|
+
output = capture_output { cli.call(arguments: %w[generate webpack]) }
|
|
10
|
+
expect(output).to eq("generate webpack. Apps: []\n")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "allows to invoke a subcommand via an inherited subcomand aliases" do
|
|
14
|
+
output = capture_output { cli.call(arguments: %w[g webpack]) }
|
|
15
|
+
expect(output).to eq("generate webpack. Apps: []\n")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "allows to override basic commands" do
|
|
19
|
+
output = capture_output { cli.call(arguments: ["hello"]) }
|
|
20
|
+
expect(output).to eq("hello from webpack\n")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "allows to override a subcommand" do
|
|
24
|
+
output = capture_output { cli.call(arguments: %w[sub command]) }
|
|
25
|
+
expect(output).to eq("override from webpack\n")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "callbacks" do
|
|
29
|
+
it "allows to add callbacks as a block" do
|
|
30
|
+
expected = <<~OUTPUT
|
|
31
|
+
before command callback Webpack::CLI::CallbacksCommand {:url=>"https://hanamirb.test", :dir=>"."}
|
|
32
|
+
before callback (class), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
|
|
33
|
+
before callback (object), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
|
|
34
|
+
dir: ., url: "https://hanamirb.test"
|
|
35
|
+
after command callback Webpack::CLI::CallbacksCommand {:url=>"https://hanamirb.test", :dir=>"."}
|
|
36
|
+
after callback (class), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
|
|
37
|
+
after callback (object), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
|
|
38
|
+
OUTPUT
|
|
39
|
+
|
|
40
|
+
output = capture_output { cli.call(arguments: %w[callbacks . --url=https://hanamirb.test]) }
|
|
41
|
+
expect(output).to eq(expected)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "allows to call array option" do
|
|
46
|
+
output = capture_output { cli.call(arguments: %w[generate webpack --apps=test,api,admin]) }
|
|
47
|
+
expect(output).to eq("generate webpack. Apps: [\"test\", \"api\", \"admin\"]\n")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# this file is managed by dry-rb/devtools project
|
|
4
|
+
|
|
5
|
+
require "warning"
|
|
6
|
+
|
|
7
|
+
Warning.ignore(%r{rspec/core})
|
|
8
|
+
Warning.ignore(%r{rspec/mocks})
|
|
9
|
+
Warning.ignore(/codacy/)
|
|
10
|
+
Warning[:experimental] = false if Warning.respond_to?(:[])
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe "CLI" do
|
|
4
|
+
context "when registry" do
|
|
5
|
+
context "passing module" do
|
|
6
|
+
include_examples "Commands", WithRegistry
|
|
7
|
+
include_examples "Rendering", WithRegistry
|
|
8
|
+
include_examples "Subcommands", WithRegistry
|
|
9
|
+
include_examples "Inherited commands", WithBlock
|
|
10
|
+
include_examples "Third-party gems", WithRegistry
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
context "passing block" do
|
|
14
|
+
include_examples "Commands", WithBlock
|
|
15
|
+
include_examples "Rendering", WithBlock
|
|
16
|
+
include_examples "Subcommands", WithBlock
|
|
17
|
+
include_examples "Inherited commands", WithBlock
|
|
18
|
+
include_examples "Third-party gems", WithBlock
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "passing block with no arguments" do
|
|
22
|
+
include_examples "Commands", WithZeroArityBlock
|
|
23
|
+
include_examples "Rendering", WithZeroArityBlock
|
|
24
|
+
include_examples "Subcommands", WithZeroArityBlock
|
|
25
|
+
include_examples "Inherited commands", WithZeroArityBlock
|
|
26
|
+
include_examples "Third-party gems", WithZeroArityBlock
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "with command" do
|
|
31
|
+
let(:cli) { Dry.CLI(Baz::CLI) }
|
|
32
|
+
let(:cmd) { File.basename($PROGRAM_NAME, File.extname($PROGRAM_NAME)) }
|
|
33
|
+
|
|
34
|
+
it "shows help" do
|
|
35
|
+
output = capture_output { cli.call(arguments: ["-h"]) }
|
|
36
|
+
expected_output = <<~OUTPUT
|
|
37
|
+
Command:
|
|
38
|
+
#{cmd}
|
|
39
|
+
|
|
40
|
+
Usage:
|
|
41
|
+
#{cmd} MANDATORY_ARG [OPTIONAL_ARG]
|
|
42
|
+
|
|
43
|
+
Description:
|
|
44
|
+
Baz command line interface
|
|
45
|
+
|
|
46
|
+
Arguments:
|
|
47
|
+
MANDATORY_ARG # REQUIRED Mandatory argument
|
|
48
|
+
OPTIONAL_ARG # Optional argument (has to have default value in call method)
|
|
49
|
+
|
|
50
|
+
Options:
|
|
51
|
+
--option-one=VALUE, -1 VALUE # Option one
|
|
52
|
+
--[no-]boolean-option, -b # Option boolean
|
|
53
|
+
--option-with-default=VALUE, -d VALUE # Option default, default: "test"
|
|
54
|
+
--help, -h # Print this help
|
|
55
|
+
OUTPUT
|
|
56
|
+
expect(output).to eq(expected_output)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "with required_argument" do
|
|
60
|
+
output = capture_output { cli.call(arguments: ["first_arg"]) }
|
|
61
|
+
expect(output).to eq(
|
|
62
|
+
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
|
|
63
|
+
"Options: {:option_with_default=>\"test\"}\n"
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "with optional_arg" do
|
|
68
|
+
output = capture_output { cli.call(arguments: %w[first_arg opt_arg]) }
|
|
69
|
+
expect(output).to eq(
|
|
70
|
+
"mandatory_arg: first_arg. optional_arg: opt_arg. " \
|
|
71
|
+
"Options: {:option_with_default=>\"test\", :args=>[\"opt_arg\"]}\n"
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "with underscored option_one" do
|
|
76
|
+
output = capture_output { cli.call(arguments: %w[first_arg --option_one=test2]) }
|
|
77
|
+
expect(output).to eq(
|
|
78
|
+
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
|
|
79
|
+
"Options: {:option_with_default=>\"test\", :option_one=>\"test2\"}\n"
|
|
80
|
+
)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "with option_one alias" do
|
|
84
|
+
output = capture_output { cli.call(arguments: %w[first_arg -1 test2]) }
|
|
85
|
+
expect(output).to eq(
|
|
86
|
+
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
|
|
87
|
+
"Options: {:option_with_default=>\"test\", :option_one=>\"test2\"}\n"
|
|
88
|
+
)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "with underscored boolean_option" do
|
|
92
|
+
output = capture_output { cli.call(arguments: %w[first_arg --boolean_option]) }
|
|
93
|
+
expect(output).to eq(
|
|
94
|
+
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
|
|
95
|
+
"Options: {:option_with_default=>\"test\", :boolean_option=>true}\n"
|
|
96
|
+
)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "with boolean_option alias" do
|
|
100
|
+
output = capture_output { cli.call(arguments: %w[first_arg -b]) }
|
|
101
|
+
expect(output).to eq(
|
|
102
|
+
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
|
|
103
|
+
"Options: {:option_with_default=>\"test\", :boolean_option=>true}\n"
|
|
104
|
+
)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "with underscoreed option_with_default alias" do
|
|
108
|
+
output = capture_output { cli.call(arguments: %w[first_arg --option_with_default=test3]) }
|
|
109
|
+
expect(output).to eq(
|
|
110
|
+
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
|
|
111
|
+
"Options: {:option_with_default=>\"test3\"}\n"
|
|
112
|
+
)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "with combination of aliases" do
|
|
116
|
+
output = capture_output { cli.call(arguments: %w[first_arg -bd test3]) }
|
|
117
|
+
expect(output).to eq(
|
|
118
|
+
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
|
|
119
|
+
"Options: {:option_with_default=>\"test3\", :boolean_option=>true}\n"
|
|
120
|
+
)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Dry::CLI::Inflector do
|
|
4
|
+
describe ".dasherize" do
|
|
5
|
+
it "returns nil if input is nil" do
|
|
6
|
+
expect(described_class.dasherize(nil)).to be(nil)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "downcases input" do
|
|
10
|
+
expect(described_class.dasherize("Dry")).to eq("dry")
|
|
11
|
+
expect(described_class.dasherize("CLI")).to eq("cli")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "replaces spaces with dashes" do
|
|
15
|
+
expect(described_class.dasherize("Command Line Interface")).to eq("command-line-interface")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "replaces underscores with dashes" do
|
|
19
|
+
expect(described_class.dasherize("fast_code_reloading")).to eq("fast-code-reloading")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "accepts any object that respond to #to_s" do
|
|
23
|
+
expect(described_class.dasherize(:dry)).to eq("dry")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Dry::CLI::Registry do
|
|
4
|
+
describe ".before" do
|
|
5
|
+
context "when command can't be found" do
|
|
6
|
+
it "raises error" do
|
|
7
|
+
expect do
|
|
8
|
+
Bar::CLI::Commands.before("pixel") { puts "hello" }
|
|
9
|
+
end.to raise_error(
|
|
10
|
+
Dry::CLI::UnknownCommandError,
|
|
11
|
+
"unknown command: `pixel'"
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context "when object is given" do
|
|
17
|
+
it "raises error when it doesn't respond to #call" do
|
|
18
|
+
callback = Object.new
|
|
19
|
+
|
|
20
|
+
expect do
|
|
21
|
+
Bar::CLI::Commands.before("alpha", callback)
|
|
22
|
+
end.to raise_error(
|
|
23
|
+
Dry::CLI::InvalidCallbackError,
|
|
24
|
+
"expected `#{callback.inspect}' to respond to `#call'"
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "when class is given" do
|
|
30
|
+
it "raises error when #initialize arity is not equal to 0" do
|
|
31
|
+
callback = Struct
|
|
32
|
+
|
|
33
|
+
expect do
|
|
34
|
+
Bar::CLI::Commands.before("alpha", callback)
|
|
35
|
+
end.to raise_error(
|
|
36
|
+
Dry::CLI::InvalidCallbackError,
|
|
37
|
+
"expected `#{callback.inspect}' to respond to `#initialize' with arity 0"
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe ".after" do
|
|
44
|
+
context "when command can't be found" do
|
|
45
|
+
it "raises error" do
|
|
46
|
+
expect do
|
|
47
|
+
Bar::CLI::Commands.after("peta") { puts "hello" }
|
|
48
|
+
end.to raise_error(Dry::CLI::UnknownCommandError, "unknown command: `peta'")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "when object is given" do
|
|
53
|
+
it "raises error when it doesn't respond to #call" do
|
|
54
|
+
callback = Object.new
|
|
55
|
+
|
|
56
|
+
expect do
|
|
57
|
+
Bar::CLI::Commands.after("alpha", callback)
|
|
58
|
+
end.to raise_error(
|
|
59
|
+
Dry::CLI::InvalidCallbackError,
|
|
60
|
+
"expected `#{callback.inspect}' to respond to `#call'"
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "when class is given" do
|
|
66
|
+
it "raises error when #initialize arity is not equal to 0" do
|
|
67
|
+
callback = Struct
|
|
68
|
+
|
|
69
|
+
expect do
|
|
70
|
+
Bar::CLI::Commands.after("alpha", callback)
|
|
71
|
+
end.to raise_error(
|
|
72
|
+
Dry::CLI::InvalidCallbackError,
|
|
73
|
+
"expected `#{callback.inspect}' to respond to `#initialize' with arity 0"
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Change log
|
|
2
|
+
|
|
3
|
+
## [v0.3.0] - unreleased
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
* Add support for the majority of the ECMA-48 & VT100 terminal controls
|
|
7
|
+
* Add support for hyperlinks escape sequences ([@radarek])
|
|
8
|
+
|
|
9
|
+
## [v0.2.0] - 2019-11-12
|
|
10
|
+
|
|
11
|
+
### Change
|
|
12
|
+
* Change gemspec to include metadata
|
|
13
|
+
* Change gemspec to limit Ruby version to >= 2.0
|
|
14
|
+
* Change gemspec to relax dev dependency of bundler version
|
|
15
|
+
|
|
16
|
+
## [v0.1.0] - 2018-08-27
|
|
17
|
+
|
|
18
|
+
* Initial implementation and release
|
|
19
|
+
|
|
20
|
+
[@radarek]: https://github.com/radarek
|
|
21
|
+
|
|
22
|
+
[v0.3.0]: https://github.com/piotrmurach/strings-ansi/compare/v0.2.0...v0.3.0
|
|
23
|
+
[v0.2.0]: https://github.com/piotrmurach/strings-ansi/compare/v0.1.0...v0.2.0
|
|
24
|
+
[v0.1.0]: https://github.com/piotrmurach/strings-ansi/compare/aa66ce8...v0.1.0
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at [email]. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img width="225" src="https://github.com/piotrmurach/strings/blob/master/assets/strings_logo.png" alt="Strings logo" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
# Strings::ANSI
|
|
6
|
+
|
|
7
|
+
[][gem]
|
|
8
|
+
[][gh_actions_ci]
|
|
9
|
+
[][appveyor]
|
|
10
|
+
[][codeclimate]
|
|
11
|
+
[][coverage]
|
|
12
|
+
[][inchpages]
|
|
13
|
+
|
|
14
|
+
[gem]: http://badge.fury.io/rb/strings-ansi
|
|
15
|
+
[gh_actions_ci]: https://github.com/piotrmurach/strings-ansi/actions?query=workflow%3ACI
|
|
16
|
+
[appveyor]: https://ci.appveyor.com/project/piotrmurach/strings-ansi
|
|
17
|
+
[codeclimate]: https://codeclimate.com/github/piotrmurach/strings-ansi/maintainability
|
|
18
|
+
[coverage]: https://coveralls.io/github/piotrmurach/strings-ansi?branch=master
|
|
19
|
+
[inchpages]: http://inch-ci.org/github/piotrmurach/strings-ansi
|
|
20
|
+
|
|
21
|
+
> Handle ANSI escape codes in strings.
|
|
22
|
+
|
|
23
|
+
**Strings::ANSI** provides ANSI handling component for [Strings](https://github.com/piotrmurach/strings).
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
Add this line to your application's Gemfile:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
gem 'strings-ansi'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
And then execute:
|
|
34
|
+
|
|
35
|
+
$ bundle
|
|
36
|
+
|
|
37
|
+
Or install it yourself as:
|
|
38
|
+
|
|
39
|
+
$ gem install strings-ansi
|
|
40
|
+
|
|
41
|
+
## Contents
|
|
42
|
+
|
|
43
|
+
* [1. Usage](#1-usage)
|
|
44
|
+
* [2. API](#2-api)
|
|
45
|
+
* [2.1 ansi?](#21-ansi)
|
|
46
|
+
* [2.2 only_ansi?](#22-only_ansi)
|
|
47
|
+
* [2.3 sanitize](#23-sanitize)
|
|
48
|
+
* [3. Extending String class](#3-extending-string-class)
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
The `Strings::ANSI` is a module that can check if a string has ANSI escape codes:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
Strings::ANSI.ansi?("\e[32mHello\e[0m")
|
|
56
|
+
# => true
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
It can also check if a string consists of only ANSI codes:
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
Strings::ANSI.only_ansi?("\e[32mHello\e[0m")
|
|
63
|
+
# => false
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Finally, you can remove any ANSI codes from a string:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
Strings::ANSI.sanitize("\e[32mHello\e[0m")
|
|
70
|
+
# => "Hello"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 2. API
|
|
74
|
+
|
|
75
|
+
### 2.1 ansi?
|
|
76
|
+
|
|
77
|
+
To check if a string includes ANSI escape codes use `ansi?` like so:
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
Strings::ANSI.ansi?("\e[33;44mfoo\e[0m")
|
|
81
|
+
# => true
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 2.2 only_ansi?
|
|
85
|
+
|
|
86
|
+
To check if a string includes only ANSI escape codes use `only_ansi?`:
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
Strings::ANSI.only_ansi?("\e[33;44mfoo\e[0m")
|
|
90
|
+
# => false
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 2.3 sanitize
|
|
94
|
+
|
|
95
|
+
To remove ANSI codes from a string use `sanitize`:
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
Strings::ANSI.sanitize("\e[0;33;49mHello\e[0m")
|
|
99
|
+
# => Hello
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 3. Extending String class
|
|
103
|
+
|
|
104
|
+
Though it is highly discouraged to pollute core Ruby classes, you can add the required methods to `String` class by using refinements.
|
|
105
|
+
|
|
106
|
+
For example, if you wish to only extend strings with `sanitize` method do:
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
module MyStringExt
|
|
110
|
+
refine String do
|
|
111
|
+
def sanitize
|
|
112
|
+
Strings::ANSI.sanitize(self)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
This will make `sanitize` method available for any strings where refinement is applied:
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
using MyStringExt
|
|
122
|
+
|
|
123
|
+
string.sanitize("\e[32mHello\e[0m")
|
|
124
|
+
# => Hello
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Alternatively, if you want to include all the **Strings::ANSI** methods:
|
|
128
|
+
|
|
129
|
+
```ruby
|
|
130
|
+
require 'strings/ansi/extensions'
|
|
131
|
+
|
|
132
|
+
using Strings::ANSI::Extensions
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Development
|
|
136
|
+
|
|
137
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
138
|
+
|
|
139
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
140
|
+
|
|
141
|
+
## Contributing
|
|
142
|
+
|
|
143
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/piotrmurach/strings-ansi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
148
|
+
|
|
149
|
+
## Code of Conduct
|
|
150
|
+
|
|
151
|
+
Everyone interacting in the Strings::ANSI project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/strings-ansi/blob/master/CODE_OF_CONDUCT.md).
|
|
152
|
+
|
|
153
|
+
## Copyright
|
|
154
|
+
|
|
155
|
+
Copyright (c) 2018 Piotr Murach. See LICENSE for further details.
|