command_kit 0.4.1 → 0.5.1

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.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.rubocop.yml +7 -1
  4. data/ChangeLog.md +11 -0
  5. data/Gemfile +2 -0
  6. data/README.md +3 -0
  7. data/Rakefile +2 -0
  8. data/command_kit.gemspec +8 -6
  9. data/lib/command_kit/arguments/argument.rb +3 -1
  10. data/lib/command_kit/arguments/argument_value.rb +2 -0
  11. data/lib/command_kit/arguments.rb +5 -5
  12. data/lib/command_kit/bug_report.rb +4 -2
  13. data/lib/command_kit/colors.rb +2 -2
  14. data/lib/command_kit/command.rb +13 -11
  15. data/lib/command_kit/command_name.rb +3 -1
  16. data/lib/command_kit/commands/auto_load/subcommand.rb +3 -1
  17. data/lib/command_kit/commands/auto_load.rb +3 -3
  18. data/lib/command_kit/commands/auto_require.rb +5 -3
  19. data/lib/command_kit/commands/command.rb +4 -2
  20. data/lib/command_kit/commands/help.rb +2 -2
  21. data/lib/command_kit/commands/parent_command.rb +2 -0
  22. data/lib/command_kit/commands/subcommand.rb +2 -0
  23. data/lib/command_kit/commands.rb +8 -8
  24. data/lib/command_kit/completion/install.rb +277 -0
  25. data/lib/command_kit/description.rb +3 -1
  26. data/lib/command_kit/edit.rb +1 -1
  27. data/lib/command_kit/env/home.rb +1 -1
  28. data/lib/command_kit/env/path.rb +1 -1
  29. data/lib/command_kit/env/prefix.rb +41 -0
  30. data/lib/command_kit/env/shell.rb +58 -0
  31. data/lib/command_kit/env.rb +2 -0
  32. data/lib/command_kit/examples.rb +4 -2
  33. data/lib/command_kit/exception_handler.rb +4 -2
  34. data/lib/command_kit/file_utils.rb +2 -0
  35. data/lib/command_kit/help/man.rb +4 -4
  36. data/lib/command_kit/help.rb +2 -0
  37. data/lib/command_kit/interactive.rb +1 -1
  38. data/lib/command_kit/main.rb +2 -0
  39. data/lib/command_kit/open_app.rb +4 -2
  40. data/lib/command_kit/options/option.rb +3 -1
  41. data/lib/command_kit/options/option_value.rb +2 -2
  42. data/lib/command_kit/options/parser.rb +3 -3
  43. data/lib/command_kit/options/quiet.rb +3 -1
  44. data/lib/command_kit/options/verbose.rb +3 -1
  45. data/lib/command_kit/options/version.rb +3 -1
  46. data/lib/command_kit/options.rb +5 -3
  47. data/lib/command_kit/os/linux.rb +3 -1
  48. data/lib/command_kit/os.rb +2 -0
  49. data/lib/command_kit/package_manager.rb +6 -4
  50. data/lib/command_kit/pager.rb +4 -4
  51. data/lib/command_kit/printing/fields.rb +3 -1
  52. data/lib/command_kit/printing/indent.rb +2 -0
  53. data/lib/command_kit/printing/lists.rb +1 -1
  54. data/lib/command_kit/printing/tables/border_style.rb +2 -0
  55. data/lib/command_kit/printing/tables/row_builder.rb +3 -1
  56. data/lib/command_kit/printing/tables/style.rb +1 -1
  57. data/lib/command_kit/printing/tables/table_builder.rb +3 -1
  58. data/lib/command_kit/printing/tables.rb +4 -4
  59. data/lib/command_kit/printing.rb +1 -1
  60. data/lib/command_kit/program_name.rb +2 -0
  61. data/lib/command_kit/stdio.rb +2 -0
  62. data/lib/command_kit/sudo.rb +1 -1
  63. data/lib/command_kit/terminal.rb +4 -2
  64. data/lib/command_kit/usage.rb +4 -2
  65. data/lib/command_kit/version.rb +3 -1
  66. data/lib/command_kit/xdg.rb +4 -2
  67. data/lib/command_kit.rb +4 -2
  68. metadata +5 -65
  69. data/spec/arguments/argument_spec.rb +0 -133
  70. data/spec/arguments/argument_value_spec.rb +0 -66
  71. data/spec/arguments_spec.rb +0 -279
  72. data/spec/bug_report_spec.rb +0 -266
  73. data/spec/colors_spec.rb +0 -771
  74. data/spec/command_kit_spec.rb +0 -8
  75. data/spec/command_name_spec.rb +0 -130
  76. data/spec/command_spec.rb +0 -123
  77. data/spec/commands/auto_load/subcommand_spec.rb +0 -82
  78. data/spec/commands/auto_load_spec.rb +0 -159
  79. data/spec/commands/auto_require_spec.rb +0 -142
  80. data/spec/commands/fixtures/test_auto_load/cli/commands/test1.rb +0 -10
  81. data/spec/commands/fixtures/test_auto_load/cli/commands/test2.rb +0 -10
  82. data/spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb +0 -10
  83. data/spec/commands/help_spec.rb +0 -66
  84. data/spec/commands/parent_command_spec.rb +0 -40
  85. data/spec/commands/subcommand_spec.rb +0 -99
  86. data/spec/commands_spec.rb +0 -865
  87. data/spec/description_spec.rb +0 -179
  88. data/spec/edit_spec.rb +0 -72
  89. data/spec/env/home_spec.rb +0 -46
  90. data/spec/env/path_spec.rb +0 -84
  91. data/spec/env_spec.rb +0 -123
  92. data/spec/examples_spec.rb +0 -211
  93. data/spec/exception_handler_spec.rb +0 -103
  94. data/spec/file_utils_spec.rb +0 -59
  95. data/spec/fixtures/template.erb +0 -5
  96. data/spec/help/man_spec.rb +0 -345
  97. data/spec/help_spec.rb +0 -94
  98. data/spec/inflector_spec.rb +0 -166
  99. data/spec/interactive_spec.rb +0 -415
  100. data/spec/main_spec.rb +0 -179
  101. data/spec/man_spec.rb +0 -46
  102. data/spec/open_app_spec.rb +0 -85
  103. data/spec/options/option_spec.rb +0 -343
  104. data/spec/options/option_value_spec.rb +0 -171
  105. data/spec/options/parser_spec.rb +0 -274
  106. data/spec/options/quiet_spec.rb +0 -51
  107. data/spec/options/verbose_spec.rb +0 -51
  108. data/spec/options/version_spec.rb +0 -146
  109. data/spec/options_spec.rb +0 -465
  110. data/spec/os/linux_spec.rb +0 -164
  111. data/spec/os_spec.rb +0 -233
  112. data/spec/package_manager_spec.rb +0 -806
  113. data/spec/pager_spec.rb +0 -217
  114. data/spec/printing/fields_spec.rb +0 -167
  115. data/spec/printing/indent_spec.rb +0 -132
  116. data/spec/printing/lists_spec.rb +0 -99
  117. data/spec/printing/tables/border_style.rb +0 -43
  118. data/spec/printing/tables/cell_builer_spec.rb +0 -135
  119. data/spec/printing/tables/row_builder_spec.rb +0 -165
  120. data/spec/printing/tables/style_spec.rb +0 -377
  121. data/spec/printing/tables/table_builder_spec.rb +0 -252
  122. data/spec/printing/tables/table_formatter_spec.rb +0 -1190
  123. data/spec/printing/tables_spec.rb +0 -1069
  124. data/spec/printing_spec.rb +0 -106
  125. data/spec/program_name_spec.rb +0 -70
  126. data/spec/spec_helper.rb +0 -3
  127. data/spec/stdio_spec.rb +0 -264
  128. data/spec/sudo_spec.rb +0 -51
  129. data/spec/terminal_spec.rb +0 -231
  130. data/spec/usage_spec.rb +0 -237
  131. data/spec/xdg_spec.rb +0 -191
@@ -1,66 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/commands/help'
3
- require 'command_kit/commands'
4
-
5
- describe CommandKit::Commands::Help do
6
- module TestHelpCommand
7
- class CLI
8
- include CommandKit::Commands
9
-
10
- class Test < CommandKit::Command
11
- end
12
-
13
- class TestWithoutHelp
14
- end
15
-
16
- command Test
17
- command 'test-without-help', TestWithoutHelp
18
- end
19
- end
20
-
21
- let(:parent_command_class) { TestHelpCommand::CLI }
22
- let(:parent_command) { parent_command_class.new }
23
- let(:command_class) { CommandKit::Commands::Help }
24
-
25
- subject { command_class.new(parent_command: parent_command) }
26
-
27
- describe ".run" do
28
- context "when giving no arguments" do
29
- it "must call the parent command's #help method" do
30
- expect(parent_command).to receive(:help).with(no_args)
31
-
32
- subject.run
33
- end
34
- end
35
-
36
- context "when given a command name" do
37
- let(:command) { 'test' }
38
-
39
- it "must lookup the command and call it's #help method" do
40
- expect_any_instance_of(parent_command_class::Test).to receive(:help)
41
-
42
- subject.run(command)
43
- end
44
-
45
- context "but the command does not define a #help method" do
46
- let(:command) { 'test-without-help' }
47
-
48
- it do
49
- expect { subject.run(command) }.to raise_error(TypeError)
50
- end
51
- end
52
-
53
- context "but the command name is invalid" do
54
- let(:command) { 'xxx' }
55
-
56
- it "must print an error message and exit with 1" do
57
- expect(subject).to receive(:exit).with(1)
58
-
59
- expect { subject.run(command) }.to output(
60
- "#{subject.command_name}: unknown command: #{command}#{$/}"
61
- ).to_stderr
62
- end
63
- end
64
- end
65
- end
66
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/commands'
3
- require 'command_kit/commands/parent_command'
4
-
5
- describe CommandKit::Commands::ParentCommand do
6
- module TestParentCommand
7
- class TestCommands
8
-
9
- include CommandKit::Commands
10
-
11
- class Test < CommandKit::Command
12
- include CommandKit::Commands::ParentCommand
13
- end
14
-
15
- command Test
16
-
17
- end
18
- end
19
-
20
- let(:parent_command_class) { TestParentCommand::TestCommands }
21
- let(:command_class) { TestParentCommand::TestCommands::Test }
22
-
23
- describe "#initialize" do
24
- context "when given a parent_command: keyword argument" do
25
- let(:parent_command) { parent_command_class.new }
26
-
27
- subject { command_class.new(parent_command: parent_command) }
28
-
29
- it "must initialize #parent_command" do
30
- expect(subject.parent_command).to be(parent_command)
31
- end
32
- end
33
-
34
- context "when the parent_command: keyword argument is not given" do
35
- it do
36
- expect { command_class.new }.to raise_error(ArgumentError)
37
- end
38
- end
39
- end
40
- end
@@ -1,99 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/commands/subcommand'
3
- require 'command_kit/command'
4
-
5
- describe CommandKit::Commands::Subcommand do
6
- module TestSubcommands
7
- class TestCommand < CommandKit::Command
8
- end
9
-
10
- class TestCommandWithoutDescription
11
- end
12
-
13
- class TestCommandWithASentenceFragmentDescription
14
- include CommandKit::Description
15
-
16
- description "The quick brown fox"
17
- end
18
-
19
- class TestCommandWithASingleSentenceDescription
20
- include CommandKit::Description
21
-
22
- description "The quick brown fox jumps over the lazy dog."
23
- end
24
-
25
- class TestCommandWithAMultiSentenceDescription
26
- include CommandKit::Description
27
-
28
- description "The quick brown fox jumps over the lazy dog. Foo bar baz."
29
- end
30
- end
31
-
32
- describe "#initialize" do
33
- let(:command_class) { TestSubcommands::TestCommand }
34
-
35
- subject { described_class.new(command_class) }
36
-
37
- it "must initialize the subcommand with a given command class" do
38
- expect(subject.command).to be(command_class)
39
- end
40
-
41
- context "when the command class has no description" do
42
- it "#summary must be nil" do
43
- expect(subject.summary).to be(nil)
44
- end
45
- end
46
-
47
- context "when the command class have a description" do
48
- let(:command_class) { TestSubcommands::TestCommandWithAMultiSentenceDescription }
49
-
50
- it "must extract the summary using .summary" do
51
- expect(subject.summary).to eq(described_class.summary(command_class))
52
- end
53
- end
54
-
55
- context "when given aliases:" do
56
- let(:aliases) { %w[test t] }
57
-
58
- subject { described_class.new(command_class, aliases: aliases) }
59
-
60
- it "must initialize #aliases" do
61
- expect(subject.aliases).to eq(aliases)
62
- end
63
- end
64
- end
65
-
66
- describe ".summary" do
67
- subject { described_class.summary(command_class) }
68
-
69
- context "when the command class does respond_to?(:description)" do
70
- let(:command_class) { TestSubcommands::TestCommandWithoutDescription }
71
-
72
- it { expect(subject).to be(nil) }
73
- end
74
-
75
- context "when the command class has a sentence fragment description" do
76
- let(:command_class) { TestSubcommands::TestCommandWithASentenceFragmentDescription }
77
-
78
- it "must return the sentence fragment" do
79
- expect(subject).to eq(command_class.description)
80
- end
81
- end
82
-
83
- context "when the command class has a single sentence description" do
84
- let(:command_class) { TestSubcommands::TestCommandWithASingleSentenceDescription }
85
-
86
- it "must return the single sentence without the terminating period" do
87
- expect(subject).to eq(command_class.description.chomp('.'))
88
- end
89
- end
90
-
91
- context "when the command class has a multi-sentence description" do
92
- let(:command_class) { TestSubcommands::TestCommandWithAMultiSentenceDescription }
93
-
94
- it "must extract the first sentence, without the terminating period" do
95
- expect(subject).to eq(command_class.description.split(/\.\s*/).first)
96
- end
97
- end
98
- end
99
- end