command_kit 0.1.0.pre1 → 0.2.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.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +15 -0
  3. data/.rubocop.yml +138 -0
  4. data/ChangeLog.md +34 -2
  5. data/Gemfile +3 -0
  6. data/README.md +135 -214
  7. data/Rakefile +3 -2
  8. data/command_kit.gemspec +4 -4
  9. data/examples/colors.rb +30 -0
  10. data/examples/command.rb +65 -0
  11. data/examples/pager.rb +30 -0
  12. data/gemspec.yml +10 -2
  13. data/lib/command_kit/arguments/argument.rb +16 -44
  14. data/lib/command_kit/arguments/argument_value.rb +3 -30
  15. data/lib/command_kit/arguments.rb +66 -20
  16. data/lib/command_kit/colors.rb +253 -45
  17. data/lib/command_kit/command.rb +50 -3
  18. data/lib/command_kit/command_name.rb +9 -0
  19. data/lib/command_kit/commands/auto_load/subcommand.rb +3 -0
  20. data/lib/command_kit/commands/auto_load.rb +16 -0
  21. data/lib/command_kit/commands/auto_require.rb +16 -0
  22. data/lib/command_kit/commands/command.rb +3 -0
  23. data/lib/command_kit/commands/help.rb +2 -0
  24. data/lib/command_kit/commands/parent_command.rb +7 -0
  25. data/lib/command_kit/commands/subcommand.rb +15 -0
  26. data/lib/command_kit/commands.rb +40 -4
  27. data/lib/command_kit/description.rb +15 -2
  28. data/lib/command_kit/env/home.rb +9 -0
  29. data/lib/command_kit/env/path.rb +15 -0
  30. data/lib/command_kit/env.rb +4 -0
  31. data/lib/command_kit/examples.rb +15 -2
  32. data/lib/command_kit/exception_handler.rb +4 -0
  33. data/lib/command_kit/help/man.rb +74 -47
  34. data/lib/command_kit/help.rb +10 -1
  35. data/lib/command_kit/inflector.rb +49 -17
  36. data/lib/command_kit/interactive.rb +239 -0
  37. data/lib/command_kit/main.rb +20 -9
  38. data/lib/command_kit/man.rb +44 -0
  39. data/lib/command_kit/open_app.rb +69 -0
  40. data/lib/command_kit/options/option.rb +36 -9
  41. data/lib/command_kit/options/option_value.rb +42 -3
  42. data/lib/command_kit/options/parser.rb +44 -17
  43. data/lib/command_kit/options/quiet.rb +3 -0
  44. data/lib/command_kit/options/verbose.rb +5 -0
  45. data/lib/command_kit/options/version.rb +6 -0
  46. data/lib/command_kit/options.rb +59 -10
  47. data/lib/command_kit/os/linux.rb +157 -0
  48. data/lib/command_kit/os.rb +165 -11
  49. data/lib/command_kit/package_manager.rb +200 -0
  50. data/lib/command_kit/pager.rb +84 -9
  51. data/lib/command_kit/printing/indent.rb +25 -2
  52. data/lib/command_kit/printing.rb +23 -0
  53. data/lib/command_kit/program_name.rb +7 -0
  54. data/lib/command_kit/stdio.rb +24 -0
  55. data/lib/command_kit/sudo.rb +40 -0
  56. data/lib/command_kit/terminal.rb +159 -0
  57. data/lib/command_kit/usage.rb +14 -0
  58. data/lib/command_kit/version.rb +1 -1
  59. data/lib/command_kit/xdg.rb +21 -1
  60. data/lib/command_kit.rb +1 -0
  61. data/spec/arguments/argument_spec.rb +5 -41
  62. data/spec/arguments/argument_value_spec.rb +1 -61
  63. data/spec/arguments_spec.rb +8 -25
  64. data/spec/colors_spec.rb +277 -13
  65. data/spec/command_name_spec.rb +1 -1
  66. data/spec/command_spec.rb +4 -1
  67. data/spec/commands/auto_load/subcommand_spec.rb +1 -1
  68. data/spec/commands/auto_load_spec.rb +1 -1
  69. data/spec/commands/auto_require_spec.rb +2 -2
  70. data/spec/commands/help_spec.rb +1 -1
  71. data/spec/commands/parent_command_spec.rb +1 -1
  72. data/spec/commands/subcommand_spec.rb +1 -1
  73. data/spec/commands_spec.rb +2 -2
  74. data/spec/description_spec.rb +1 -25
  75. data/spec/env/home_spec.rb +1 -1
  76. data/spec/env/path_spec.rb +1 -1
  77. data/spec/examples_spec.rb +1 -25
  78. data/spec/exception_handler_spec.rb +1 -1
  79. data/spec/help/man_spec.rb +316 -0
  80. data/spec/help_spec.rb +0 -25
  81. data/spec/inflector_spec.rb +71 -9
  82. data/spec/interactive_spec.rb +415 -0
  83. data/spec/main_spec.rb +7 -7
  84. data/spec/man_spec.rb +46 -0
  85. data/spec/open_app_spec.rb +85 -0
  86. data/spec/options/option_spec.rb +48 -9
  87. data/spec/options/option_value_spec.rb +53 -4
  88. data/spec/options_spec.rb +1 -1
  89. data/spec/os/linux_spec.rb +154 -0
  90. data/spec/os_spec.rb +201 -14
  91. data/spec/package_manager_spec.rb +806 -0
  92. data/spec/pager_spec.rb +78 -15
  93. data/spec/printing/indent_spec.rb +1 -1
  94. data/spec/printing_spec.rb +10 -2
  95. data/spec/program_name_spec.rb +1 -1
  96. data/spec/spec_helper.rb +0 -3
  97. data/spec/sudo_spec.rb +51 -0
  98. data/spec/{console_spec.rb → terminal_spec.rb} +65 -35
  99. data/spec/usage_spec.rb +2 -2
  100. data/spec/xdg_spec.rb +1 -1
  101. metadata +32 -13
  102. data/lib/command_kit/arguments/usage.rb +0 -6
  103. data/lib/command_kit/console.rb +0 -141
  104. data/lib/command_kit/options/usage.rb +0 -6
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
@@ -182,7 +182,7 @@ describe Usage do
182
182
  [
183
183
  "#{subject.command_name} #{command_class.usage[0]}",
184
184
  "#{subject.command_name} #{command_class.usage[1]}",
185
- "#{subject.command_name} #{command_class.usage[2]}",
185
+ "#{subject.command_name} #{command_class.usage[2]}"
186
186
  ]
187
187
  )
188
188
  end
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.pre1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-08 00:00:00.000000000 Z
11
+ date: 2021-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  description: A Ruby toolkit for building clean, correct, and robust CLI commands as
28
- Ruby classes.
28
+ plain-old Ruby classes.
29
29
  email: postmodern.mod3@gmail.com
30
30
  executables: []
31
31
  extensions: []
@@ -38,6 +38,7 @@ files:
38
38
  - ".github/workflows/ruby.yml"
39
39
  - ".gitignore"
40
40
  - ".rspec"
41
+ - ".rubocop.yml"
41
42
  - ".yardopts"
42
43
  - ChangeLog.md
43
44
  - Gemfile
@@ -45,12 +46,14 @@ files:
45
46
  - README.md
46
47
  - Rakefile
47
48
  - command_kit.gemspec
49
+ - examples/colors.rb
50
+ - examples/command.rb
51
+ - examples/pager.rb
48
52
  - gemspec.yml
49
53
  - lib/command_kit.rb
50
54
  - lib/command_kit/arguments.rb
51
55
  - lib/command_kit/arguments/argument.rb
52
56
  - lib/command_kit/arguments/argument_value.rb
53
- - lib/command_kit/arguments/usage.rb
54
57
  - lib/command_kit/colors.rb
55
58
  - lib/command_kit/command.rb
56
59
  - lib/command_kit/command_name.rb
@@ -62,7 +65,6 @@ files:
62
65
  - lib/command_kit/commands/help.rb
63
66
  - lib/command_kit/commands/parent_command.rb
64
67
  - lib/command_kit/commands/subcommand.rb
65
- - lib/command_kit/console.rb
66
68
  - lib/command_kit/description.rb
67
69
  - lib/command_kit/env.rb
68
70
  - lib/command_kit/env/home.rb
@@ -72,21 +74,27 @@ files:
72
74
  - lib/command_kit/help.rb
73
75
  - lib/command_kit/help/man.rb
74
76
  - lib/command_kit/inflector.rb
77
+ - lib/command_kit/interactive.rb
75
78
  - lib/command_kit/main.rb
79
+ - lib/command_kit/man.rb
80
+ - lib/command_kit/open_app.rb
76
81
  - lib/command_kit/options.rb
77
82
  - lib/command_kit/options/option.rb
78
83
  - lib/command_kit/options/option_value.rb
79
84
  - lib/command_kit/options/parser.rb
80
85
  - lib/command_kit/options/quiet.rb
81
- - lib/command_kit/options/usage.rb
82
86
  - lib/command_kit/options/verbose.rb
83
87
  - lib/command_kit/options/version.rb
84
88
  - lib/command_kit/os.rb
89
+ - lib/command_kit/os/linux.rb
90
+ - lib/command_kit/package_manager.rb
85
91
  - lib/command_kit/pager.rb
86
92
  - lib/command_kit/printing.rb
87
93
  - lib/command_kit/printing/indent.rb
88
94
  - lib/command_kit/program_name.rb
89
95
  - lib/command_kit/stdio.rb
96
+ - lib/command_kit/sudo.rb
97
+ - lib/command_kit/terminal.rb
90
98
  - lib/command_kit/usage.rb
91
99
  - lib/command_kit/version.rb
92
100
  - lib/command_kit/xdg.rb
@@ -107,34 +115,45 @@ files:
107
115
  - spec/commands/parent_command_spec.rb
108
116
  - spec/commands/subcommand_spec.rb
109
117
  - spec/commands_spec.rb
110
- - spec/console_spec.rb
111
118
  - spec/description_spec.rb
112
119
  - spec/env/home_spec.rb
113
120
  - spec/env/path_spec.rb
114
121
  - spec/env_spec.rb
115
122
  - spec/examples_spec.rb
116
123
  - spec/exception_handler_spec.rb
124
+ - spec/help/man_spec.rb
117
125
  - spec/help_spec.rb
118
126
  - spec/inflector_spec.rb
127
+ - spec/interactive_spec.rb
119
128
  - spec/main_spec.rb
129
+ - spec/man_spec.rb
130
+ - spec/open_app_spec.rb
120
131
  - spec/options/option_spec.rb
121
132
  - spec/options/option_value_spec.rb
122
133
  - spec/options/parser_spec.rb
123
134
  - spec/options_spec.rb
135
+ - spec/os/linux_spec.rb
124
136
  - spec/os_spec.rb
137
+ - spec/package_manager_spec.rb
125
138
  - spec/pager_spec.rb
126
139
  - spec/printing/indent_spec.rb
127
140
  - spec/printing_spec.rb
128
141
  - spec/program_name_spec.rb
129
142
  - spec/spec_helper.rb
130
143
  - spec/stdio_spec.rb
144
+ - spec/sudo_spec.rb
145
+ - spec/terminal_spec.rb
131
146
  - spec/usage_spec.rb
132
147
  - spec/xdg_spec.rb
133
- homepage: https://github.com/postmodern/command_kit#readme
148
+ homepage: https://github.com/postmodern/command_kit.rb#readme
134
149
  licenses:
135
150
  - MIT
136
- metadata: {}
137
- post_install_message:
151
+ metadata:
152
+ documentation_uri: https://rubydoc.info/gems/command_kit
153
+ source_code_uri: https://github.com/postmodern/command_kit.rb
154
+ bug_tracker_uri: https://github.com/postmodern/command_kit.rb/issues
155
+ changelog_uri: https://github.com/postmodern/command_kit.rb/blob/main/ChangeLog.md
156
+ post_install_message:
138
157
  rdoc_options: []
139
158
  require_paths:
140
159
  - lib
@@ -149,8 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
168
  - !ruby/object:Gem::Version
150
169
  version: '0'
151
170
  requirements: []
152
- rubygems_version: 3.1.6
153
- signing_key:
171
+ rubygems_version: 3.2.22
172
+ signing_key:
154
173
  specification_version: 4
155
174
  summary: A toolkit for building Ruby CLI commands
156
175
  test_files: []
@@ -1,6 +0,0 @@
1
- module CommandKit
2
- module Arguments
3
- module Usage
4
- end
5
- end
6
- end
@@ -1,141 +0,0 @@
1
- require 'command_kit/stdio'
2
- require 'command_kit/env'
3
-
4
- begin
5
- require 'io/console'
6
- rescue LoadError
7
- end
8
-
9
- module CommandKit
10
- #
11
- # Provides access to [IO.console] and [IO.console_size].
12
- #
13
- # ## Environment Variables
14
- #
15
- # * `LINES` - The explicit number of lines or rows the console should have.
16
- # * `COLUMNS` - The explicit number of columns the console should have.
17
- #
18
- # [IO.console]: https://rubydoc.info/gems/io-console/IO#console-class_method
19
- # [IO#winsize]: https://rubydoc.info/gems/io-console/IO#winsize-instance_method
20
- #
21
- module Console
22
- include Stdio
23
- include Env
24
-
25
- # The default console height to fallback to.
26
- DEFAULT_HEIGHT = 25
27
-
28
- # The default console width to fallback to.
29
- DEFAULT_WIDTH = 80
30
-
31
- #
32
- # Initializes any console settings.
33
- #
34
- # @param [Hash{Symbol => Object}] kwargs
35
- # Additional keyword arguments.
36
- #
37
- # @note
38
- # If the `$LINES` env variable is set, and is non-zero, it will be
39
- # returned by {#console_height}.
40
- #
41
- # @note
42
- # If the `$COLUMNS` env variable is set, and is non-zero, it will be
43
- # returned by {#console_width}.
44
- #
45
- def initialize(**kwargs)
46
- super(**kwargs)
47
-
48
- @default_console_height = if (lines = env['LINES'])
49
- lines.to_i
50
- else
51
- DEFAULT_HEIGHT
52
- end
53
-
54
- @default_console_width = if (columns = env['COLUMNS'])
55
- columns.to_i
56
- else
57
- DEFAULT_WIDTH
58
- end
59
- end
60
-
61
- #
62
- # Determines if there is a console present.
63
- #
64
- # @return [Boolean]
65
- # Specifies whether {Stdio#stdout stdout} is connected to a console.
66
- #
67
- def console?
68
- IO.respond_to?(:console) && stdout.tty?
69
- end
70
-
71
- #
72
- # Returns the console object, if {Stdio#stdout stdout} is connected to a
73
- # console.
74
- #
75
- # @return [IO, nil]
76
- # The IO objects or `nil` if {Stdio#stdout stdout} is not connected to a
77
- # console.
78
- #
79
- # @example
80
- # console
81
- # # => #<File:/dev/tty>
82
- #
83
- def console
84
- IO.console if console?
85
- end
86
-
87
- #
88
- # Returns the console's height in number of lines.
89
- #
90
- # @return [Integer]
91
- # The console's height in number of lines.
92
- #
93
- # @example
94
- # console_height
95
- # # => 22
96
- #
97
- def console_height
98
- if (console = self.console)
99
- console.winsize[0]
100
- else
101
- @default_console_height
102
- end
103
- end
104
-
105
- #
106
- # Returns the console's width in number of lines.
107
- #
108
- # @return [Integer]
109
- # The console's width in number of columns.
110
- #
111
- # @example
112
- # console_width
113
- # # => 91
114
- #
115
- def console_width
116
- if (console = self.console)
117
- console.winsize[1]
118
- else
119
- @default_console_width
120
- end
121
- end
122
-
123
- #
124
- # The console height (lines) and width (columns).
125
- #
126
- # @return [(Integer, Integer)]
127
- # Returns the height and width of the console.
128
- #
129
- # @example
130
- # console_size
131
- # # => [23, 91]
132
- #
133
- def console_size
134
- if (console = self.console)
135
- console.winsize
136
- else
137
- [@default_console_height, @default_console_width]
138
- end
139
- end
140
- end
141
- end
@@ -1,6 +0,0 @@
1
- module CommandKit
2
- module Options
3
- module Usage
4
- end
5
- end
6
- end