command_kit 0.1.0.pre1

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 (98) hide show
  1. checksums.yaml +7 -0
  2. data/.document +3 -0
  3. data/.github/workflows/ruby.yml +29 -0
  4. data/.gitignore +7 -0
  5. data/.rspec +1 -0
  6. data/.yardopts +1 -0
  7. data/ChangeLog.md +29 -0
  8. data/Gemfile +14 -0
  9. data/LICENSE.txt +20 -0
  10. data/README.md +283 -0
  11. data/Rakefile +23 -0
  12. data/command_kit.gemspec +60 -0
  13. data/gemspec.yml +14 -0
  14. data/lib/command_kit.rb +1 -0
  15. data/lib/command_kit/arguments.rb +161 -0
  16. data/lib/command_kit/arguments/argument.rb +111 -0
  17. data/lib/command_kit/arguments/argument_value.rb +81 -0
  18. data/lib/command_kit/arguments/usage.rb +6 -0
  19. data/lib/command_kit/colors.rb +355 -0
  20. data/lib/command_kit/command.rb +42 -0
  21. data/lib/command_kit/command_name.rb +95 -0
  22. data/lib/command_kit/commands.rb +299 -0
  23. data/lib/command_kit/commands/auto_load.rb +153 -0
  24. data/lib/command_kit/commands/auto_load/subcommand.rb +90 -0
  25. data/lib/command_kit/commands/auto_require.rb +138 -0
  26. data/lib/command_kit/commands/command.rb +12 -0
  27. data/lib/command_kit/commands/help.rb +43 -0
  28. data/lib/command_kit/commands/parent_command.rb +21 -0
  29. data/lib/command_kit/commands/subcommand.rb +51 -0
  30. data/lib/command_kit/console.rb +141 -0
  31. data/lib/command_kit/description.rb +89 -0
  32. data/lib/command_kit/env.rb +43 -0
  33. data/lib/command_kit/env/home.rb +71 -0
  34. data/lib/command_kit/env/path.rb +71 -0
  35. data/lib/command_kit/examples.rb +99 -0
  36. data/lib/command_kit/exception_handler.rb +55 -0
  37. data/lib/command_kit/help.rb +62 -0
  38. data/lib/command_kit/help/man.rb +125 -0
  39. data/lib/command_kit/inflector.rb +84 -0
  40. data/lib/command_kit/main.rb +103 -0
  41. data/lib/command_kit/options.rb +179 -0
  42. data/lib/command_kit/options/option.rb +171 -0
  43. data/lib/command_kit/options/option_value.rb +90 -0
  44. data/lib/command_kit/options/parser.rb +227 -0
  45. data/lib/command_kit/options/quiet.rb +53 -0
  46. data/lib/command_kit/options/usage.rb +6 -0
  47. data/lib/command_kit/options/verbose.rb +55 -0
  48. data/lib/command_kit/options/version.rb +62 -0
  49. data/lib/command_kit/os.rb +47 -0
  50. data/lib/command_kit/pager.rb +115 -0
  51. data/lib/command_kit/printing.rb +32 -0
  52. data/lib/command_kit/printing/indent.rb +78 -0
  53. data/lib/command_kit/program_name.rb +57 -0
  54. data/lib/command_kit/stdio.rb +138 -0
  55. data/lib/command_kit/usage.rb +102 -0
  56. data/lib/command_kit/version.rb +4 -0
  57. data/lib/command_kit/xdg.rb +138 -0
  58. data/spec/arguments/argument_spec.rb +169 -0
  59. data/spec/arguments/argument_value_spec.rb +126 -0
  60. data/spec/arguments_spec.rb +213 -0
  61. data/spec/colors_spec.rb +470 -0
  62. data/spec/command_kit_spec.rb +8 -0
  63. data/spec/command_name_spec.rb +130 -0
  64. data/spec/command_spec.rb +49 -0
  65. data/spec/commands/auto_load/subcommand_spec.rb +82 -0
  66. data/spec/commands/auto_load_spec.rb +128 -0
  67. data/spec/commands/auto_require_spec.rb +142 -0
  68. data/spec/commands/fixtures/test_auto_load/cli/commands/test1.rb +10 -0
  69. data/spec/commands/fixtures/test_auto_load/cli/commands/test2.rb +10 -0
  70. data/spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb +10 -0
  71. data/spec/commands/help_spec.rb +66 -0
  72. data/spec/commands/parent_command_spec.rb +40 -0
  73. data/spec/commands/subcommand_spec.rb +99 -0
  74. data/spec/commands_spec.rb +767 -0
  75. data/spec/console_spec.rb +201 -0
  76. data/spec/description_spec.rb +203 -0
  77. data/spec/env/home_spec.rb +46 -0
  78. data/spec/env/path_spec.rb +78 -0
  79. data/spec/env_spec.rb +123 -0
  80. data/spec/examples_spec.rb +235 -0
  81. data/spec/exception_handler_spec.rb +103 -0
  82. data/spec/help_spec.rb +119 -0
  83. data/spec/inflector_spec.rb +104 -0
  84. data/spec/main_spec.rb +179 -0
  85. data/spec/options/option_spec.rb +258 -0
  86. data/spec/options/option_value_spec.rb +67 -0
  87. data/spec/options/parser_spec.rb +265 -0
  88. data/spec/options_spec.rb +137 -0
  89. data/spec/os_spec.rb +46 -0
  90. data/spec/pager_spec.rb +154 -0
  91. data/spec/printing/indent_spec.rb +130 -0
  92. data/spec/printing_spec.rb +76 -0
  93. data/spec/program_name_spec.rb +62 -0
  94. data/spec/spec_helper.rb +6 -0
  95. data/spec/stdio_spec.rb +264 -0
  96. data/spec/usage_spec.rb +237 -0
  97. data/spec/xdg_spec.rb +191 -0
  98. metadata +156 -0
data/spec/xdg_spec.rb ADDED
@@ -0,0 +1,191 @@
1
+ require 'spec_helper'
2
+ require 'command_kit/xdg'
3
+
4
+ describe XDG do
5
+ module TestXDG
6
+ class TestCommand
7
+ include CommandKit::XDG
8
+ end
9
+ end
10
+
11
+ let(:command_class) { TestXDG::TestCommand }
12
+ subject { command_class.new }
13
+
14
+ describe ".xdg_namespace" do
15
+ subject { command_class }
16
+
17
+ context "when no xdg_namespace has been defined" do
18
+ it "must default to the .command_name" do
19
+ expect(subject.xdg_namespace).to eq(subject.command_name)
20
+ end
21
+ end
22
+
23
+ context "when an xdg_namespace has been defined in a super-class" do
24
+ module TestXDG
25
+ class SuperClassWithXDGNamespace
26
+ include CommandKit::XDG
27
+
28
+ xdg_namespace 'foo'
29
+ end
30
+
31
+ class SubClassWithoutXDGNamespace < SuperClassWithXDGNamespace
32
+ end
33
+ end
34
+
35
+ let(:command_superclass) { TestXDG::SuperClassWithXDGNamespace }
36
+ let(:command_class) { TestXDG::SubClassWithoutXDGNamespace }
37
+
38
+ it "must default to the superclass'es .xdg_namespace" do
39
+ expect(subject.xdg_namespace).to eq(command_superclass.xdg_namespace)
40
+ end
41
+
42
+ context "but the sub-class also defines an .xdg_namespace" do
43
+ module TestXDG
44
+ class SubClassWithXDGNamespace < SuperClassWithXDGNamespace
45
+
46
+ xdg_namespace 'bar'
47
+
48
+ end
49
+ end
50
+
51
+ let(:command_class) { TestXDG::SubClassWithXDGNamespace }
52
+
53
+ it "must return the subclass'es .xdg_namespace" do
54
+ expect(command_class.xdg_namespace).to eq('bar')
55
+ end
56
+
57
+ it "must not override the superclass'es .xdg_namespace" do
58
+ expect(command_superclass.xdg_namespace).to eq('foo')
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "#xdg_namespace" do
65
+ it "must return .xdg_namespace" do
66
+ expect(subject.xdg_namespace).to eq(command_class.xdg_namespace)
67
+ end
68
+ end
69
+
70
+ let(:xdg_config_home) { '/path/to/.config' }
71
+ let(:xdg_data_home) { '/path/to/.local/share' }
72
+ let(:xdg_cache_home) { '/path/to/.cache' }
73
+
74
+ describe "#initialize" do
75
+ let(:xdg_namespace) { subject.xdg_namespace }
76
+
77
+ context "when env: contains 'XDG_CONFIG_HOME'" do
78
+ let(:env) do
79
+ {'XDG_CONFIG_HOME' => xdg_config_home}
80
+ end
81
+
82
+ subject { command_class.new(env: env) }
83
+
84
+ it "must initialize #config_dir to '$XDG_CONFIG_HOME/<xdg_namespace>'" do
85
+ expect(subject.config_dir).to eq(
86
+ File.join(xdg_config_home,xdg_namespace)
87
+ )
88
+ end
89
+ end
90
+
91
+ context "when env: does not contains 'XDG_DATA_HOME'" do
92
+ it "must initialize #config_dir to '$HOME/.config/<xdg_namespace>'" do
93
+ expect(subject.config_dir).to eq(
94
+ File.join(subject.home_dir,'.config',subject.xdg_namespace)
95
+ )
96
+ end
97
+ end
98
+
99
+ context "when env: contains 'XDG_DATA_HOME'" do
100
+ let(:env) do
101
+ {'XDG_DATA_HOME' => xdg_data_home}
102
+ end
103
+
104
+ subject { command_class.new(env: env) }
105
+
106
+ it "must initialize #local_share_dir to '$XDG_DATA_HOME/<xdg_namespace>'" do
107
+ expect(subject.local_share_dir).to eq(
108
+ File.join(xdg_data_home,xdg_namespace)
109
+ )
110
+ end
111
+ end
112
+
113
+ context "when env: does not contains 'XDG_DATA_HOME'" do
114
+ it "must initialize #local_share_dir to '$HOME/.local/share/<xdg_namespace>'" do
115
+ expect(subject.local_share_dir).to eq(
116
+ File.join(subject.home_dir,'.local','share',xdg_namespace)
117
+ )
118
+ end
119
+ end
120
+
121
+ context "when env: contains 'XDG_CACHE_HOME'" do
122
+ let(:env) do
123
+ {'XDG_CACHE_HOME' => xdg_cache_home}
124
+ end
125
+
126
+ subject { command_class.new(env: env) }
127
+
128
+ it "must initialize #cache_dir to '$XDG_CACHE_HOME/<xdg_namespace>'" do
129
+ expect(subject.cache_dir).to eq(
130
+ File.join(xdg_cache_home,xdg_namespace)
131
+ )
132
+ end
133
+ end
134
+
135
+ context "when env: does not contains 'XDG_CACHE_HOME'" do
136
+ it "must initialize #cache_dir to '$HOME/.cache/<xdg_namespace>'" do
137
+ expect(subject.cache_dir).to eq(
138
+ File.join(subject.home_dir,'.cache',xdg_namespace)
139
+ )
140
+ end
141
+ end
142
+ end
143
+
144
+ describe "#config_dir" do
145
+ let(:env) do
146
+ {'XDG_CONFIG_HOME' => xdg_config_home}
147
+ end
148
+
149
+ subject { command_class.new(env: env) }
150
+
151
+ let(:xdg_namespace) { subject.xdg_namespace }
152
+
153
+ it "must return the initialized #config_dir" do
154
+ expect(subject.config_dir).to eq(
155
+ File.join(xdg_config_home,xdg_namespace)
156
+ )
157
+ end
158
+ end
159
+
160
+ describe "#local_share_dir" do
161
+ let(:env) do
162
+ {'XDG_DATA_HOME' => xdg_data_home}
163
+ end
164
+
165
+ subject { command_class.new(env: env) }
166
+
167
+ let(:xdg_namespace) { subject.xdg_namespace }
168
+
169
+ it "must return the initialized #local_share_dir" do
170
+ expect(subject.local_share_dir).to eq(
171
+ File.join(xdg_data_home,xdg_namespace)
172
+ )
173
+ end
174
+ end
175
+
176
+ describe "#cache_dir" do
177
+ let(:env) do
178
+ {'XDG_CACHE_HOME' => xdg_cache_home}
179
+ end
180
+
181
+ subject { command_class.new(env: env) }
182
+
183
+ let(:xdg_namespace) { subject.xdg_namespace }
184
+
185
+ it "must return the initialized #cache_dir" do
186
+ expect(subject.cache_dir).to eq(
187
+ File.join(xdg_cache_home,xdg_namespace)
188
+ )
189
+ end
190
+ end
191
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: command_kit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre1
5
+ platform: ruby
6
+ authors:
7
+ - Postmodern
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: A Ruby toolkit for building clean, correct, and robust CLI commands as
28
+ Ruby classes.
29
+ email: postmodern.mod3@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - ChangeLog.md
34
+ - LICENSE.txt
35
+ - README.md
36
+ files:
37
+ - ".document"
38
+ - ".github/workflows/ruby.yml"
39
+ - ".gitignore"
40
+ - ".rspec"
41
+ - ".yardopts"
42
+ - ChangeLog.md
43
+ - Gemfile
44
+ - LICENSE.txt
45
+ - README.md
46
+ - Rakefile
47
+ - command_kit.gemspec
48
+ - gemspec.yml
49
+ - lib/command_kit.rb
50
+ - lib/command_kit/arguments.rb
51
+ - lib/command_kit/arguments/argument.rb
52
+ - lib/command_kit/arguments/argument_value.rb
53
+ - lib/command_kit/arguments/usage.rb
54
+ - lib/command_kit/colors.rb
55
+ - lib/command_kit/command.rb
56
+ - lib/command_kit/command_name.rb
57
+ - lib/command_kit/commands.rb
58
+ - lib/command_kit/commands/auto_load.rb
59
+ - lib/command_kit/commands/auto_load/subcommand.rb
60
+ - lib/command_kit/commands/auto_require.rb
61
+ - lib/command_kit/commands/command.rb
62
+ - lib/command_kit/commands/help.rb
63
+ - lib/command_kit/commands/parent_command.rb
64
+ - lib/command_kit/commands/subcommand.rb
65
+ - lib/command_kit/console.rb
66
+ - lib/command_kit/description.rb
67
+ - lib/command_kit/env.rb
68
+ - lib/command_kit/env/home.rb
69
+ - lib/command_kit/env/path.rb
70
+ - lib/command_kit/examples.rb
71
+ - lib/command_kit/exception_handler.rb
72
+ - lib/command_kit/help.rb
73
+ - lib/command_kit/help/man.rb
74
+ - lib/command_kit/inflector.rb
75
+ - lib/command_kit/main.rb
76
+ - lib/command_kit/options.rb
77
+ - lib/command_kit/options/option.rb
78
+ - lib/command_kit/options/option_value.rb
79
+ - lib/command_kit/options/parser.rb
80
+ - lib/command_kit/options/quiet.rb
81
+ - lib/command_kit/options/usage.rb
82
+ - lib/command_kit/options/verbose.rb
83
+ - lib/command_kit/options/version.rb
84
+ - lib/command_kit/os.rb
85
+ - lib/command_kit/pager.rb
86
+ - lib/command_kit/printing.rb
87
+ - lib/command_kit/printing/indent.rb
88
+ - lib/command_kit/program_name.rb
89
+ - lib/command_kit/stdio.rb
90
+ - lib/command_kit/usage.rb
91
+ - lib/command_kit/version.rb
92
+ - lib/command_kit/xdg.rb
93
+ - spec/arguments/argument_spec.rb
94
+ - spec/arguments/argument_value_spec.rb
95
+ - spec/arguments_spec.rb
96
+ - spec/colors_spec.rb
97
+ - spec/command_kit_spec.rb
98
+ - spec/command_name_spec.rb
99
+ - spec/command_spec.rb
100
+ - spec/commands/auto_load/subcommand_spec.rb
101
+ - spec/commands/auto_load_spec.rb
102
+ - spec/commands/auto_require_spec.rb
103
+ - spec/commands/fixtures/test_auto_load/cli/commands/test1.rb
104
+ - spec/commands/fixtures/test_auto_load/cli/commands/test2.rb
105
+ - spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb
106
+ - spec/commands/help_spec.rb
107
+ - spec/commands/parent_command_spec.rb
108
+ - spec/commands/subcommand_spec.rb
109
+ - spec/commands_spec.rb
110
+ - spec/console_spec.rb
111
+ - spec/description_spec.rb
112
+ - spec/env/home_spec.rb
113
+ - spec/env/path_spec.rb
114
+ - spec/env_spec.rb
115
+ - spec/examples_spec.rb
116
+ - spec/exception_handler_spec.rb
117
+ - spec/help_spec.rb
118
+ - spec/inflector_spec.rb
119
+ - spec/main_spec.rb
120
+ - spec/options/option_spec.rb
121
+ - spec/options/option_value_spec.rb
122
+ - spec/options/parser_spec.rb
123
+ - spec/options_spec.rb
124
+ - spec/os_spec.rb
125
+ - spec/pager_spec.rb
126
+ - spec/printing/indent_spec.rb
127
+ - spec/printing_spec.rb
128
+ - spec/program_name_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/stdio_spec.rb
131
+ - spec/usage_spec.rb
132
+ - spec/xdg_spec.rb
133
+ homepage: https://github.com/postmodern/command_kit#readme
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 2.7.0
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubygems_version: 3.1.6
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: A toolkit for building Ruby CLI commands
156
+ test_files: []