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
@@ -34,6 +34,8 @@ module CommandKit
34
34
  # @param [IO] stderr
35
35
  # The stderr error output stream. Defaults to `$stderr`.
36
36
  #
37
+ # @api public
38
+ #
37
39
  def initialize(stdin: nil, stdout: nil, stderr: nil, **kwargs)
38
40
  @stdin = stdin
39
41
  @stdout = stdout
@@ -48,6 +50,8 @@ module CommandKit
48
50
  # @return [$stdin, IO]
49
51
  # The initialized `@stdin` value or `$stdin`.
50
52
  #
53
+ # @api public
54
+ #
51
55
  def stdin
52
56
  @stdin || $stdin
53
57
  end
@@ -58,6 +62,8 @@ module CommandKit
58
62
  # @return [$stdout, IO]
59
63
  # The initialized `@stdout` value or `$stdout`.
60
64
  #
65
+ # @api public
66
+ #
61
67
  def stdout
62
68
  @stdout || $stdout
63
69
  end
@@ -68,6 +74,8 @@ module CommandKit
68
74
  # @return [$stderr, IO]
69
75
  # The initialized `@stderr` value or `$stderr`.
70
76
  #
77
+ # @api public
78
+ #
71
79
  def stderr
72
80
  @stderr || $stderr
73
81
  end
@@ -75,6 +83,8 @@ module CommandKit
75
83
  #
76
84
  # Calls `stdin.gets`.
77
85
  #
86
+ # @api public
87
+ #
78
88
  def gets(*arguments)
79
89
  stdin.gets(*arguments)
80
90
  end
@@ -82,6 +92,8 @@ module CommandKit
82
92
  #
83
93
  # Calls `stdin.readline`.
84
94
  #
95
+ # @api public
96
+ #
85
97
  def readline(*arguments)
86
98
  stdin.readline(*arguments)
87
99
  end
@@ -89,6 +101,8 @@ module CommandKit
89
101
  #
90
102
  # Calls `stdin.readlines`.
91
103
  #
104
+ # @api public
105
+ #
92
106
  def readlines(*arguments)
93
107
  stdin.readlines(*arguments)
94
108
  end
@@ -99,6 +113,8 @@ module CommandKit
99
113
  #
100
114
  # Calls `stdout.putc`.
101
115
  #
116
+ # @api public
117
+ #
102
118
  def putc(*arguments)
103
119
  stdout.putc(*arguments)
104
120
  end
@@ -106,6 +122,8 @@ module CommandKit
106
122
  #
107
123
  # Calls `stdout.puts`.
108
124
  #
125
+ # @api public
126
+ #
109
127
  def puts(*arguments)
110
128
  stdout.puts(*arguments)
111
129
  end
@@ -113,6 +131,8 @@ module CommandKit
113
131
  #
114
132
  # Calls `stdout.print`.
115
133
  #
134
+ # @api public
135
+ #
116
136
  def print(*arguments)
117
137
  stdout.print(*arguments)
118
138
  end
@@ -120,6 +140,8 @@ module CommandKit
120
140
  #
121
141
  # Calls `stdout.printf`.
122
142
  #
143
+ # @api public
144
+ #
123
145
  def printf(*arguments)
124
146
  stdout.printf(*arguments)
125
147
  end
@@ -130,6 +152,8 @@ module CommandKit
130
152
  # @param [String, nil] message
131
153
  # The optional abort message.
132
154
  #
155
+ # @api public
156
+ #
133
157
  def abort(message=nil)
134
158
  stderr.puts(message) if message
135
159
  exit(1)
@@ -41,6 +41,8 @@ module CommandKit
41
41
  # If the `$COLUMNS` env variable is set, and is non-zero, it will be
42
42
  # returned by {#terminal_width}.
43
43
  #
44
+ # @api public
45
+ #
44
46
  def initialize(**kwargs)
45
47
  super(**kwargs)
46
48
 
@@ -63,6 +65,8 @@ module CommandKit
63
65
  # @return [Boolean]
64
66
  # Specifies whether {Stdio#stdout stdout} is connected to a terminal.
65
67
  #
68
+ # @api public
69
+ #
66
70
  def terminal?
67
71
  IO.respond_to?(:console) && stdout.tty?
68
72
  end
@@ -81,6 +85,8 @@ module CommandKit
81
85
  #
82
86
  # @see https://rubydoc.info/gems/io-console/IO
83
87
  #
88
+ # @api semipublic
89
+ #
84
90
  def terminal
85
91
  IO.console if terminal?
86
92
  end
@@ -95,6 +101,8 @@ module CommandKit
95
101
  # terminal_height
96
102
  # # => 22
97
103
  #
104
+ # @api public
105
+ #
98
106
  def terminal_height
99
107
  if (terminal = self.terminal)
100
108
  terminal.winsize[0]
@@ -113,6 +121,8 @@ module CommandKit
113
121
  # terminal_width
114
122
  # # => 91
115
123
  #
124
+ # @api public
125
+ #
116
126
  def terminal_width
117
127
  if (terminal = self.terminal)
118
128
  terminal.winsize[1]
@@ -131,6 +141,8 @@ module CommandKit
131
141
  # terminal_size
132
142
  # # => [23, 91]
133
143
  #
144
+ # @api public
145
+ #
134
146
  def terminal_size
135
147
  if (terminal = self.terminal)
136
148
  terminal.winsize
@@ -15,6 +15,9 @@ module CommandKit
15
15
  include CommandName
16
16
  include Help
17
17
 
18
+ #
19
+ # @api private
20
+ #
18
21
  module ModuleMethods
19
22
  #
20
23
  # Extends {ClassMethods} or {ModuleMethods}, depending on whether {Usage}
@@ -50,6 +53,11 @@ module CommandKit
50
53
  # @return [String, Array<String>]
51
54
  # The class'es or superclass'es usage string(s).
52
55
  #
56
+ # @example
57
+ # usage "[options] ARG1 ARG2 [ARG3 ...]"
58
+ #
59
+ # @api public
60
+ #
53
61
  def usage(new_usage=nil)
54
62
  if new_usage
55
63
  @usage = new_usage
@@ -65,6 +73,8 @@ module CommandKit
65
73
  #
66
74
  # @return [Array<String>, String, nil]
67
75
  #
76
+ # @api public
77
+ #
68
78
  def usage
69
79
  case (usage = self.class.usage)
70
80
  when Array
@@ -77,6 +87,8 @@ module CommandKit
77
87
  #
78
88
  # Prints the `usage: ...` output.
79
89
  #
90
+ # @api semipublic
91
+ #
80
92
  def help_usage
81
93
  case (usage = self.usage)
82
94
  when Array
@@ -95,6 +107,8 @@ module CommandKit
95
107
  #
96
108
  # @see #help_usage
97
109
  #
110
+ # @api public
111
+ #
98
112
  def help
99
113
  help_usage
100
114
  end
@@ -1,4 +1,4 @@
1
1
  module CommandKit
2
2
  # command_kit version
3
- VERSION = "0.1.0.rc1"
3
+ VERSION = "0.1.0"
4
4
  end
@@ -24,6 +24,9 @@ module CommandKit
24
24
  include CommandName
25
25
  include Env::Home
26
26
 
27
+ #
28
+ # @api private
29
+ #
27
30
  module ModuleMethods
28
31
  #
29
32
  # Extends {ClassMethods} or {ModuleMethods}, depending on whether {XDG} is
@@ -61,6 +64,8 @@ module CommandKit
61
64
  # {CommandName::ClassMethods#command_name} if no {#xdg_namespace} has
62
65
  # been defined.
63
66
  #
67
+ # @api public
68
+ #
64
69
  def xdg_namespace(new_namespace=nil)
65
70
  if new_namespace
66
71
  @xdg_namespace = new_namespace.to_s
@@ -77,16 +82,22 @@ module CommandKit
77
82
  # The `~/.config/<xdg_namespace>` directory.
78
83
  #
79
84
  # @return [String]
85
+ #
86
+ # @api public
80
87
  attr_reader :config_dir
81
88
 
82
89
  # The `~/.local/share/<xdg_namespace>` directory.
83
90
  #
84
91
  # @return [String]
92
+ #
93
+ # @api public
85
94
  attr_reader :local_share_dir
86
95
 
87
96
  # The `~/.cache/<xdg_namespace>` directory.
88
97
  #
89
98
  # @return [String]
99
+ #
100
+ # @api public
90
101
  attr_reader :cache_dir
91
102
 
92
103
  #
@@ -138,6 +149,8 @@ module CommandKit
138
149
  #
139
150
  # @see ClassMethods#xdg_namespace
140
151
  #
152
+ # @api semipublic
153
+ #
141
154
  def xdg_namespace
142
155
  self.class.xdg_namespace
143
156
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/arguments/argument'
3
3
 
4
- describe Arguments::Argument do
4
+ describe CommandKit::Arguments::Argument do
5
5
  let(:name) { :foo }
6
6
  let(:usage) { 'FOO' }
7
7
  let(:required) { true }
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/arguments'
3
3
 
4
- describe Arguments do
4
+ describe CommandKit::Arguments do
5
5
  module TestArguments
6
6
  class ImplicitCmd
7
7
  include CommandKit::Arguments
@@ -13,8 +13,8 @@ describe Arguments do
13
13
  describe ".included" do
14
14
  subject { command_class }
15
15
 
16
- it { expect(subject).to include(Main) }
17
- it { expect(subject).to include(Help) }
16
+ it { expect(subject).to include(CommandKit::Main) }
17
+ it { expect(subject).to include(CommandKit::Help) }
18
18
  end
19
19
 
20
20
  describe ".arguments" do
@@ -192,29 +192,5 @@ describe Arguments do
192
192
 
193
193
  subject.help
194
194
  end
195
-
196
- context "when the superclass defines it's own #help method" do
197
- module TestDescription
198
- class SuperclassHelpMethod
199
- def help
200
- puts 'superclass'
201
- end
202
- end
203
-
204
- class InheritedHelpMethod < SuperclassHelpMethod
205
- include CommandKit::Arguments
206
- end
207
- end
208
-
209
- let(:super_command_class) { TestDescription::SuperclassHelpMethod }
210
- let(:command_class) { TestDescription::InheritedHelpMethod }
211
-
212
- it "must call the superclass'es #help method first" do
213
- expect_any_instance_of(super_command_class).to receive(:help)
214
- expect(subject).to receive(:help_arguments)
215
-
216
- subject.help
217
- end
218
- end
219
195
  end
220
196
  end
data/spec/colors_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/colors'
3
3
 
4
- describe Colors do
4
+ describe CommandKit::Colors do
5
5
  module TestColors
6
6
  class TestCommand
7
7
  include CommandKit::Colors
@@ -11,10 +11,10 @@ describe Colors do
11
11
  let(:command_class) { TestColors::TestCommand }
12
12
  subject { command_class.new }
13
13
 
14
- it { expect(described_class).to include(Stdio) }
15
- it { expect(described_class).to include(Env) }
14
+ it { expect(described_class).to include(CommandKit::Stdio) }
15
+ it { expect(described_class).to include(CommandKit::Env) }
16
16
 
17
- describe Colors::ANSI do
17
+ describe CommandKit::Colors::ANSI do
18
18
  subject { described_class }
19
19
 
20
20
  describe "RESET" do
@@ -188,7 +188,7 @@ describe Colors do
188
188
  end
189
189
  end
190
190
 
191
- describe Colors::PlainText do
191
+ describe CommandKit::Colors::PlainText do
192
192
  subject { described_class }
193
193
 
194
194
  let(:str) { 'foo' }
@@ -409,13 +409,15 @@ describe Colors do
409
409
 
410
410
  before { allow(stdout).to receive(:tty?).and_return(true) }
411
411
 
412
- it { expect(subject.colors).to be(Colors::ANSI) }
412
+ it do
413
+ expect(subject.colors).to be(described_class::ANSI)
414
+ end
413
415
 
414
416
  context "when a block is given" do
415
417
  it do
416
418
  expect { |b|
417
419
  subject.colors(&b)
418
- }.to yield_with_args(Colors::ANSI)
420
+ }.to yield_with_args(described_class::ANSI)
419
421
  end
420
422
  end
421
423
  end
@@ -424,13 +426,15 @@ describe Colors do
424
426
  let(:stdout) { StringIO.new }
425
427
  subject { command_class.new(stdout: stdout) }
426
428
 
427
- it { expect(subject.colors).to be(Colors::PlainText) }
429
+ it do
430
+ expect(subject.colors).to be(described_class::PlainText)
431
+ end
428
432
 
429
433
  context "when a block is given" do
430
434
  it do
431
435
  expect { |b|
432
436
  subject.colors(&b)
433
- }.to yield_with_args(Colors::PlainText)
437
+ }.to yield_with_args(described_class::PlainText)
434
438
  end
435
439
  end
436
440
  end
@@ -441,13 +445,15 @@ describe Colors do
441
445
 
442
446
  before { allow(stream).to receive(:tty?).and_return(true) }
443
447
 
444
- it { expect(subject.colors(stream)).to be(Colors::ANSI) }
448
+ it do
449
+ expect(subject.colors(stream)).to be(described_class::ANSI)
450
+ end
445
451
 
446
452
  context "when a block is given" do
447
453
  it do
448
454
  expect { |b|
449
455
  subject.colors(stream,&b)
450
- }.to yield_with_args(Colors::ANSI)
456
+ }.to yield_with_args(described_class::ANSI)
451
457
  end
452
458
  end
453
459
  end
@@ -455,13 +461,15 @@ describe Colors do
455
461
  context "but the alternate stream does not support ANSI" do
456
462
  let(:stream) { StringIO.new }
457
463
 
458
- it { expect(subject.colors(stream)).to be(Colors::PlainText) }
464
+ it do
465
+ expect(subject.colors(stream)).to be(described_class::PlainText)
466
+ end
459
467
 
460
468
  context "when a block is given" do
461
469
  it do
462
470
  expect { |b|
463
471
  subject.colors(stream,&b)
464
- }.to yield_with_args(Colors::PlainText)
472
+ }.to yield_with_args(described_class::PlainText)
465
473
  end
466
474
  end
467
475
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/command_name'
3
3
 
4
- describe CommandName do
4
+ describe CommandKit::CommandName do
5
5
  module TestCommandName
6
6
  class ImplicitCmd
7
7
  include CommandKit::CommandName
data/spec/command_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/command'
3
3
 
4
- describe Command do
4
+ describe CommandKit::Command do
5
5
  it "must include CommandKit::Main" do
6
6
  expect(described_class).to include(CommandKit::Main)
7
7
  end
@@ -46,4 +46,7 @@ describe Command do
46
46
  expect(described_class).to include(CommandKit::ExceptionHandler)
47
47
  end
48
48
 
49
+ it "must include FileUtils" do
50
+ expect(described_class).to include(FileUtils)
51
+ end
49
52
  end