command_kit 0.1.0.rc1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +1 -1
  3. data/README.md +7 -4
  4. data/gemspec.yml +1 -1
  5. data/lib/command_kit.rb +1 -0
  6. data/lib/command_kit/arguments.rb +16 -1
  7. data/lib/command_kit/arguments/argument.rb +2 -0
  8. data/lib/command_kit/arguments/argument_value.rb +2 -0
  9. data/lib/command_kit/colors.rb +32 -0
  10. data/lib/command_kit/command.rb +5 -0
  11. data/lib/command_kit/command_name.rb +9 -0
  12. data/lib/command_kit/commands.rb +30 -0
  13. data/lib/command_kit/commands/auto_load.rb +16 -0
  14. data/lib/command_kit/commands/auto_require.rb +16 -0
  15. data/lib/command_kit/commands/command.rb +3 -0
  16. data/lib/command_kit/commands/help.rb +2 -0
  17. data/lib/command_kit/commands/parent_command.rb +7 -0
  18. data/lib/command_kit/commands/subcommand.rb +12 -0
  19. data/lib/command_kit/description.rb +12 -1
  20. data/lib/command_kit/env.rb +4 -0
  21. data/lib/command_kit/env/home.rb +9 -0
  22. data/lib/command_kit/env/path.rb +15 -0
  23. data/lib/command_kit/examples.rb +12 -1
  24. data/lib/command_kit/exception_handler.rb +4 -0
  25. data/lib/command_kit/help.rb +7 -1
  26. data/lib/command_kit/help/man.rb +13 -0
  27. data/lib/command_kit/inflector.rb +2 -0
  28. data/lib/command_kit/interactive.rb +62 -1
  29. data/lib/command_kit/main.rb +11 -0
  30. data/lib/command_kit/options.rb +12 -0
  31. data/lib/command_kit/options/option.rb +2 -0
  32. data/lib/command_kit/options/option_value.rb +2 -0
  33. data/lib/command_kit/options/parser.rb +29 -0
  34. data/lib/command_kit/options/quiet.rb +3 -0
  35. data/lib/command_kit/options/verbose.rb +5 -0
  36. data/lib/command_kit/options/version.rb +6 -0
  37. data/lib/command_kit/os.rb +6 -0
  38. data/lib/command_kit/pager.rb +27 -0
  39. data/lib/command_kit/printing.rb +23 -0
  40. data/lib/command_kit/printing/indent.rb +23 -0
  41. data/lib/command_kit/program_name.rb +7 -0
  42. data/lib/command_kit/stdio.rb +24 -0
  43. data/lib/command_kit/terminal.rb +12 -0
  44. data/lib/command_kit/usage.rb +14 -0
  45. data/lib/command_kit/version.rb +1 -1
  46. data/lib/command_kit/xdg.rb +13 -0
  47. data/spec/arguments/argument_spec.rb +1 -1
  48. data/spec/arguments_spec.rb +3 -27
  49. data/spec/colors_spec.rb +21 -13
  50. data/spec/command_name_spec.rb +1 -1
  51. data/spec/command_spec.rb +4 -1
  52. data/spec/commands/auto_load/subcommand_spec.rb +1 -1
  53. data/spec/commands/auto_load_spec.rb +1 -1
  54. data/spec/commands/auto_require_spec.rb +2 -2
  55. data/spec/commands/help_spec.rb +1 -1
  56. data/spec/commands/parent_command_spec.rb +1 -1
  57. data/spec/commands/subcommand_spec.rb +1 -1
  58. data/spec/commands_spec.rb +1 -1
  59. data/spec/description_spec.rb +1 -25
  60. data/spec/env/home_spec.rb +1 -1
  61. data/spec/env/path_spec.rb +1 -1
  62. data/spec/examples_spec.rb +1 -25
  63. data/spec/help/man_spec.rb +1 -1
  64. data/spec/help_spec.rb +0 -25
  65. data/spec/inflector_spec.rb +1 -1
  66. data/spec/main_spec.rb +7 -7
  67. data/spec/options/option_spec.rb +3 -3
  68. data/spec/options/option_value_spec.rb +1 -1
  69. data/spec/options_spec.rb +1 -1
  70. data/spec/os_spec.rb +1 -1
  71. data/spec/pager_spec.rb +1 -1
  72. data/spec/printing/indent_spec.rb +1 -1
  73. data/spec/printing_spec.rb +10 -2
  74. data/spec/program_name_spec.rb +1 -1
  75. data/spec/spec_helper.rb +0 -3
  76. data/spec/terminal_spec.rb +1 -1
  77. data/spec/usage_spec.rb +1 -1
  78. data/spec/xdg_spec.rb +1 -1
  79. metadata +3 -3
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/commands/auto_load/subcommand'
3
3
 
4
- describe Commands::AutoLoad::Subcommand do
4
+ describe CommandKit::Commands::AutoLoad::Subcommand do
5
5
  let(:fixtures_dir) { File.expand_path('../../fixtures',__FILE__) }
6
6
 
7
7
  let(:file) { 'test1.rb' }
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/commands/auto_load'
3
3
 
4
- describe Commands::AutoLoad do
4
+ describe CommandKit::Commands::AutoLoad do
5
5
  let(:fixtures_dir) { File.expand_path('../fixtures',__FILE__) }
6
6
 
7
7
  let(:dir) { File.join(fixtures_dir,'test_auto_load','cli','commands') }
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/commands/auto_require'
3
3
 
4
- describe Commands::AutoRequire do
4
+ describe CommandKit::Commands::AutoRequire do
5
5
  let(:fixtures_dir) { File.expand_path('../fixtures',__FILE__) }
6
6
  let(:lib_dir) { File.join(fixtures_dir,'test_auto_require','lib') }
7
7
  let(:dir) { File.join('test_auto_require','cli','commands') }
@@ -126,7 +126,7 @@ describe Commands::AutoRequire do
126
126
 
127
127
  it "the .commands.default_proc must auto-require commands and return a Subcommand" do
128
128
  expect(command_class.commands[command_name]).to_not be(nil)
129
- expect(command_class.commands[command_name]).to be_kind_of(Commands::Subcommand)
129
+ expect(command_class.commands[command_name]).to be_kind_of(CommandKit::Commands::Subcommand)
130
130
  expect(command_class.commands[command_name].command).to eq(TestAutoRequire::CLI::Commands::Test1)
131
131
  end
132
132
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'command_kit/commands/help'
3
3
  require 'command_kit/commands'
4
4
 
5
- describe Commands::Help do
5
+ describe CommandKit::Commands::Help do
6
6
  module TestHelpCommand
7
7
  class CLI
8
8
  include CommandKit::Commands
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'command_kit/commands'
3
3
  require 'command_kit/commands/parent_command'
4
4
 
5
- describe Commands::ParentCommand do
5
+ describe CommandKit::Commands::ParentCommand do
6
6
  module TestParentCommand
7
7
  class TestCommands
8
8
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'command_kit/commands/subcommand'
3
3
  require 'command_kit/command'
4
4
 
5
- describe Commands::Subcommand do
5
+ describe CommandKit::Commands::Subcommand do
6
6
  module TestSubcommands
7
7
  class TestCommand < CommandKit::Command
8
8
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/commands'
3
3
 
4
- describe Commands do
4
+ describe CommandKit::Commands do
5
5
  module TestCommands
6
6
  class TestEmptyCommands
7
7
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/description'
3
3
 
4
- describe Description do
4
+ describe CommandKit::Description do
5
5
  module TestDescription
6
6
  class ImplicitCmd
7
7
  include CommandKit::Description
@@ -175,29 +175,5 @@ describe Description do
175
175
 
176
176
  subject.help
177
177
  end
178
-
179
- context "when the superclass defines it's own #help method" do
180
- module TestDescription
181
- class SuperclassHelpMethod
182
- def help
183
- puts 'superclass'
184
- end
185
- end
186
-
187
- class InheritedHelpMethod < SuperclassHelpMethod
188
- include CommandKit::Description
189
- end
190
- end
191
-
192
- let(:super_command_class) { TestDescription::SuperclassHelpMethod }
193
- let(:command_class) { TestDescription::InheritedHelpMethod }
194
-
195
- it "must call the superclass'es #help method first" do
196
- expect_any_instance_of(super_command_class).to receive(:help)
197
- expect(subject).to receive(:help_description)
198
-
199
- subject.help
200
- end
201
- end
202
178
  end
203
179
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/env/home'
3
3
 
4
- describe Env::Home do
4
+ describe CommandKit::Env::Home do
5
5
  module TestEnvHome
6
6
  class TestCommand
7
7
  include CommandKit::Env::Home
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/env/path'
3
3
 
4
- describe Env::Path do
4
+ describe CommandKit::Env::Path do
5
5
  module TestEnvPath
6
6
  class TestCommand
7
7
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/examples'
3
3
 
4
- describe Examples do
4
+ describe CommandKit::Examples do
5
5
  module TestExamples
6
6
  class ImplicitCmd
7
7
  include CommandKit::Examples
@@ -207,29 +207,5 @@ describe Examples do
207
207
 
208
208
  subject.help
209
209
  end
210
-
211
- context "when the superclass defines it's own #help method" do
212
- module TestDescription
213
- class SuperclassHelpMethod
214
- def help
215
- puts 'superclass'
216
- end
217
- end
218
-
219
- class InheritedHelpMethod < SuperclassHelpMethod
220
- include CommandKit::Examples
221
- end
222
- end
223
-
224
- let(:super_command_class) { TestDescription::SuperclassHelpMethod }
225
- let(:command_class) { TestDescription::InheritedHelpMethod }
226
-
227
- it "must call the superclass'es #help method first" do
228
- expect_any_instance_of(super_command_class).to receive(:help)
229
- expect(subject).to receive(:help_examples)
230
-
231
- subject.help
232
- end
233
- end
234
210
  end
235
211
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/help/man'
3
3
 
4
- describe Help::Man do
4
+ describe CommandKit::Help::Man do
5
5
  module TestHelpMan
6
6
  class TestCommand
7
7
  include CommandKit::Help::Man
data/spec/help_spec.rb CHANGED
@@ -90,30 +90,5 @@ describe CommandKit::Help do
90
90
  subject.help()
91
91
  end
92
92
  end
93
-
94
- context "when the superclass defines it's own #help method" do
95
- module TestHelp
96
- class SuperclassWithHelp
97
-
98
- def help
99
- puts 'superclass'
100
- end
101
-
102
- end
103
-
104
- class SubclassOfSuperclassWithHelp < SuperclassWithHelp
105
- include CommandKit::Help
106
- end
107
- end
108
-
109
- let(:command_superclass) { TestHelp::SuperclassWithHelp }
110
- let(:command_class) { TestHelp::SubclassOfSuperclassWithHelp }
111
-
112
- it "must call the superclass'es #help" do
113
- expect_any_instance_of(command_superclass).to receive(:help)
114
-
115
- subject.help()
116
- end
117
- end
118
93
  end
119
94
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/inflector'
3
3
 
4
- describe Inflector do
4
+ describe CommandKit::Inflector do
5
5
  describe ".demodularize" do
6
6
  context "when given a single class or module name" do
7
7
  let(:name) { 'Foo' }
data/spec/main_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/main'
3
3
 
4
- describe Main do
4
+ describe CommandKit::Main do
5
5
  module TestMain
6
6
  class TestCommand
7
7
  include CommandKit::Main
@@ -156,16 +156,16 @@ describe Main do
156
156
  describe "#main" do
157
157
  subject { command_class.new }
158
158
 
159
- it "must provide a default #main" do
160
- expect(subject).to respond_to(:main)
161
- end
162
-
163
159
  it "must return 0 by default" do
164
160
  expect(subject.main).to eq(0)
165
161
  end
166
162
 
167
- it "must accept arbitrary argv" do
168
- expect { subject.main([1,2,3]) }.to_not raise_error
163
+ it "must call #run with the given argv" do
164
+ argv = ["foo", "bar", "baz"]
165
+
166
+ expect(subject).to receive(:run).with(*argv)
167
+
168
+ subject.main(argv)
169
169
  end
170
170
 
171
171
  context "when #run raises SystemExit" do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/options/option'
3
3
 
4
- describe Options::Option do
4
+ describe CommandKit::Options::Option do
5
5
  let(:name) { :foo }
6
6
  let(:short) { nil }
7
7
  let(:long) { '--foo' }
@@ -82,7 +82,7 @@ describe Options::Option do
82
82
  subject { described_class.new(name, value: {type: type}, desc: desc) }
83
83
 
84
84
  it "must initialize #value" do
85
- expect(subject.value).to be_kind_of(Options::OptionValue)
85
+ expect(subject.value).to be_kind_of(CommandKit::Options::OptionValue)
86
86
  expect(subject.value.type).to eq(type)
87
87
  end
88
88
  end
@@ -91,7 +91,7 @@ describe Options::Option do
91
91
  subject { described_class.new(name, value: true, desc: desc) }
92
92
 
93
93
  it "must initialize #value with defaults" do
94
- expect(subject.value).to be_kind_of(Options::OptionValue)
94
+ expect(subject.value).to be_kind_of(CommandKit::Options::OptionValue)
95
95
  expect(subject.value.type).to eq(String)
96
96
  expect(subject.value.required?).to be(true)
97
97
  expect(subject.value.usage).to eq('STR')
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/options/option_value'
3
3
 
4
- describe Options::OptionValue do
4
+ describe CommandKit::Options::OptionValue do
5
5
  let(:type) { Integer }
6
6
  let(:usage) { 'COUNT' }
7
7
  let(:required) { true }
data/spec/options_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/options'
3
3
 
4
- describe Options do
4
+ describe CommandKit::Options do
5
5
  module TestOptions
6
6
  class ImplicitCmd
7
7
  include CommandKit::Options
data/spec/os_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/os'
3
3
 
4
- describe OS do
4
+ describe CommandKit::OS do
5
5
  class TestOS
6
6
  include CommandKit::OS
7
7
  end
data/spec/pager_spec.rb CHANGED
@@ -3,7 +3,7 @@ require 'command_kit/pager'
3
3
 
4
4
  require 'stringio'
5
5
 
6
- describe Pager do
6
+ describe CommandKit::Pager do
7
7
  module TestPager
8
8
  class TestCommand
9
9
  include CommandKit::Pager
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/printing/indent'
3
3
 
4
- describe Printing::Indent do
4
+ describe CommandKit::Printing::Indent do
5
5
  module TestIndent
6
6
  class TestCommand
7
7
  include CommandKit::Printing::Indent
@@ -3,7 +3,7 @@ require 'command_kit/printing'
3
3
 
4
4
  require 'stringio'
5
5
 
6
- describe Printing do
6
+ describe CommandKit::Printing do
7
7
  module TestPrinting
8
8
  class TestCmd
9
9
 
@@ -14,11 +14,19 @@ describe Printing do
14
14
 
15
15
  let(:command_class) { TestPrinting::TestCmd }
16
16
  subject { command_class.new }
17
+
18
+ describe "EOL" do
19
+ subject { described_class::EOL }
20
+
21
+ it "must equal $/" do
22
+ expect(subject).to eq($/)
23
+ end
24
+ end
17
25
 
18
26
  describe ".included" do
19
27
  subject { command_class }
20
28
 
21
- it { expect(command_class).to include(Stdio) }
29
+ it { expect(command_class).to include(CommandKit::Stdio) }
22
30
  end
23
31
 
24
32
  let(:nl) { $/ }
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/program_name'
3
3
 
4
- describe ProgramName do
4
+ describe CommandKit::ProgramName do
5
5
  module TestProgramName
6
6
  class TestCmd
7
7
  include CommandKit::ProgramName
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,3 @@
1
1
  require 'rspec'
2
2
  require 'simplecov'
3
3
  SimpleCov.start
4
-
5
- require 'command_kit/version'
6
- include CommandKit
@@ -3,7 +3,7 @@ require 'command_kit/terminal'
3
3
 
4
4
  require 'stringio'
5
5
 
6
- describe Terminal do
6
+ describe CommandKit::Terminal do
7
7
  module TestTerminal
8
8
  class TestCommand
9
9
  include CommandKit::Terminal
data/spec/usage_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/usage'
3
3
 
4
- describe Usage do
4
+ describe CommandKit::Usage do
5
5
  module TestUsage
6
6
  class ImplicitCmd
7
7
  include CommandKit::Usage
data/spec/xdg_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/xdg'
3
3
 
4
- describe XDG do
4
+ describe CommandKit::XDG do
5
5
  module TestXDG
6
6
  class TestCommand
7
7
  include CommandKit::XDG
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-02 00:00:00.000000000 Z
11
+ date: 2021-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,7 +134,7 @@ files:
134
134
  - spec/terminal_spec.rb
135
135
  - spec/usage_spec.rb
136
136
  - spec/xdg_spec.rb
137
- homepage: https://github.com/postmodern/command_kit#readme
137
+ homepage: https://github.com/postmodern/command_kit.rb#readme
138
138
  licenses:
139
139
  - MIT
140
140
  metadata: {}