command_kit 0.1.0.rc1 → 0.2.2

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 (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +17 -3
  3. data/.rubocop.yml +141 -0
  4. data/ChangeLog.md +102 -1
  5. data/Gemfile +3 -0
  6. data/README.md +187 -116
  7. data/Rakefile +3 -2
  8. data/command_kit.gemspec +4 -4
  9. data/examples/command.rb +1 -1
  10. data/gemspec.yml +8 -1
  11. data/lib/command_kit/arguments/argument.rb +2 -0
  12. data/lib/command_kit/arguments/argument_value.rb +2 -0
  13. data/lib/command_kit/arguments.rb +25 -6
  14. data/lib/command_kit/colors.rb +253 -45
  15. data/lib/command_kit/command.rb +6 -1
  16. data/lib/command_kit/command_name.rb +9 -0
  17. data/lib/command_kit/commands/auto_load.rb +24 -1
  18. data/lib/command_kit/commands/auto_require.rb +16 -0
  19. data/lib/command_kit/commands/command.rb +3 -0
  20. data/lib/command_kit/commands/help.rb +5 -2
  21. data/lib/command_kit/commands/parent_command.rb +7 -0
  22. data/lib/command_kit/commands/subcommand.rb +13 -1
  23. data/lib/command_kit/commands.rb +54 -9
  24. data/lib/command_kit/description.rb +12 -1
  25. data/lib/command_kit/env/home.rb +9 -0
  26. data/lib/command_kit/env/path.rb +16 -1
  27. data/lib/command_kit/env.rb +4 -0
  28. data/lib/command_kit/examples.rb +12 -1
  29. data/lib/command_kit/exception_handler.rb +4 -0
  30. data/lib/command_kit/help/man.rb +28 -31
  31. data/lib/command_kit/help.rb +7 -1
  32. data/lib/command_kit/inflector.rb +49 -17
  33. data/lib/command_kit/interactive.rb +71 -1
  34. data/lib/command_kit/main.rb +18 -9
  35. data/lib/command_kit/man.rb +44 -0
  36. data/lib/command_kit/open_app.rb +69 -0
  37. data/lib/command_kit/options/option.rb +3 -6
  38. data/lib/command_kit/options/option_value.rb +5 -2
  39. data/lib/command_kit/options/parser.rb +46 -19
  40. data/lib/command_kit/options/quiet.rb +3 -0
  41. data/lib/command_kit/options/verbose.rb +5 -0
  42. data/lib/command_kit/options/version.rb +6 -0
  43. data/lib/command_kit/options.rb +32 -7
  44. data/lib/command_kit/os/linux.rb +157 -0
  45. data/lib/command_kit/os.rb +165 -11
  46. data/lib/command_kit/package_manager.rb +200 -0
  47. data/lib/command_kit/pager.rb +73 -4
  48. data/lib/command_kit/printing/indent.rb +27 -4
  49. data/lib/command_kit/printing.rb +35 -1
  50. data/lib/command_kit/program_name.rb +7 -0
  51. data/lib/command_kit/stdio.rb +24 -0
  52. data/lib/command_kit/sudo.rb +40 -0
  53. data/lib/command_kit/terminal.rb +17 -0
  54. data/lib/command_kit/usage.rb +14 -0
  55. data/lib/command_kit/version.rb +1 -1
  56. data/lib/command_kit/xdg.rb +13 -0
  57. data/lib/command_kit.rb +1 -0
  58. data/spec/arguments/argument_spec.rb +2 -2
  59. data/spec/arguments_spec.rb +54 -28
  60. data/spec/colors_spec.rb +277 -13
  61. data/spec/command_name_spec.rb +1 -1
  62. data/spec/command_spec.rb +79 -5
  63. data/spec/commands/auto_load/subcommand_spec.rb +1 -1
  64. data/spec/commands/auto_load_spec.rb +34 -3
  65. data/spec/commands/auto_require_spec.rb +2 -2
  66. data/spec/commands/help_spec.rb +1 -1
  67. data/spec/commands/parent_command_spec.rb +1 -1
  68. data/spec/commands/subcommand_spec.rb +1 -1
  69. data/spec/commands_spec.rb +102 -30
  70. data/spec/description_spec.rb +1 -25
  71. data/spec/env/home_spec.rb +1 -1
  72. data/spec/env/path_spec.rb +7 -1
  73. data/spec/examples_spec.rb +1 -25
  74. data/spec/exception_handler_spec.rb +1 -1
  75. data/spec/help/man_spec.rb +55 -58
  76. data/spec/help_spec.rb +0 -25
  77. data/spec/inflector_spec.rb +71 -9
  78. data/spec/main_spec.rb +7 -7
  79. data/spec/man_spec.rb +46 -0
  80. data/spec/open_app_spec.rb +85 -0
  81. data/spec/options/option_spec.rb +5 -5
  82. data/spec/options/option_value_spec.rb +56 -1
  83. data/spec/options_spec.rb +283 -1
  84. data/spec/os/linux_spec.rb +164 -0
  85. data/spec/os_spec.rb +201 -14
  86. data/spec/package_manager_spec.rb +806 -0
  87. data/spec/pager_spec.rb +72 -7
  88. data/spec/printing/indent_spec.rb +8 -6
  89. data/spec/printing_spec.rb +33 -3
  90. data/spec/program_name_spec.rb +1 -1
  91. data/spec/spec_helper.rb +0 -3
  92. data/spec/sudo_spec.rb +51 -0
  93. data/spec/terminal_spec.rb +31 -1
  94. data/spec/usage_spec.rb +2 -2
  95. data/spec/xdg_spec.rb +1 -1
  96. metadata +21 -5
@@ -0,0 +1,164 @@
1
+ require 'spec_helper'
2
+ require 'command_kit/os/linux'
3
+
4
+ describe CommandKit::OS::Linux do
5
+ module TestOSLinux
6
+ class TestCommand
7
+ include CommandKit::OS::Linux
8
+ end
9
+ end
10
+
11
+ let(:command_class) { TestOSLinux::TestCommand }
12
+
13
+ describe ".linux_distro" do
14
+ subject { command_class }
15
+
16
+ context "and the /etc/fedora-release file exists" do
17
+ before do
18
+ expect(File).to receive(:file?).with("/etc/fedora-release").and_return(true)
19
+ end
20
+
21
+ it { expect(subject.linux_distro).to be(:fedora) }
22
+ end
23
+
24
+ context "and the /etc/redhat-release file exists" do
25
+ before do
26
+ allow(File).to receive(:file?).with("/etc/fedora-release").and_return(false)
27
+ expect(File).to receive(:file?).with("/etc/redhat-release").and_return(true)
28
+ end
29
+
30
+ it { expect(subject.linux_distro).to be(:redhat) }
31
+ end
32
+
33
+ context "and the /etc/debian_version file exists" do
34
+ before do
35
+ allow(File).to receive(:file?).with("/etc/fedora-release").and_return(false)
36
+ allow(File).to receive(:file?).with("/etc/redhat-release").and_return(false)
37
+ expect(File).to receive(:file?).with("/etc/debian_version").and_return(true)
38
+ end
39
+
40
+ it { expect(subject.linux_distro).to be(:debian) }
41
+ end
42
+
43
+ context "and the /etc/SuSE-release file exists" do
44
+ before do
45
+ allow(File).to receive(:file?).with("/etc/fedora-release").and_return(false)
46
+ allow(File).to receive(:file?).with("/etc/redhat-release").and_return(false)
47
+ allow(File).to receive(:file?).with("/etc/debian_version").and_return(false)
48
+ expect(File).to receive(:file?).with("/etc/SuSE-release").and_return(true)
49
+ end
50
+
51
+ it { expect(subject.linux_distro).to be(:suse) }
52
+ end
53
+
54
+ context "and the /etc/arch-release file exists" do
55
+ before do
56
+ allow(File).to receive(:file?).with("/etc/fedora-release").and_return(false)
57
+ allow(File).to receive(:file?).with("/etc/redhat-release").and_return(false)
58
+ allow(File).to receive(:file?).with("/etc/debian_version").and_return(false)
59
+ allow(File).to receive(:file?).with("/etc/SuSE-release").and_return(false)
60
+ expect(File).to receive(:file?).with("/etc/arch-release").and_return(true)
61
+ end
62
+
63
+ it { expect(subject.linux_distro).to be(:arch) }
64
+ end
65
+ end
66
+
67
+ subject { command_class.new }
68
+
69
+ describe "#initialize" do
70
+ it "must default #linux_distro to self.class.linux_distro" do
71
+ expect(subject.linux_distro).to eq(command_class.linux_distro)
72
+ end
73
+
74
+ context "when the linux_distro: keyword is given" do
75
+ let(:linux_distro) { :suse }
76
+
77
+ subject { command_class.new(linux_distro: linux_distro) }
78
+
79
+ it "must set #linux_distro" do
80
+ expect(subject.linux_distro).to eq(linux_distro)
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "#redhat_linux?" do
86
+ subject { command_class.new(linux_distro: linux_distro) }
87
+
88
+ context "when #linux_distro is :redhat" do
89
+ let(:linux_distro) { :redhat }
90
+
91
+ it { expect(subject.redhat_linux?).to be(true) }
92
+ end
93
+
94
+ context "when #linux_distro is not :redhat" do
95
+ let(:linux_distro) { :debian }
96
+
97
+ it { expect(subject.redhat_linux?).to be(false) }
98
+ end
99
+ end
100
+
101
+ describe "#fedora_linux?" do
102
+ subject { command_class.new(linux_distro: linux_distro) }
103
+
104
+ context "when #linux_distro is :fedora" do
105
+ let(:linux_distro) { :fedora }
106
+
107
+ it { expect(subject.fedora_linux?).to be(true) }
108
+ end
109
+
110
+ context "when #linux_distro is not :fedora" do
111
+ let(:linux_distro) { :debian }
112
+
113
+ it { expect(subject.fedora_linux?).to be(false) }
114
+ end
115
+ end
116
+
117
+ describe "#debian_linux?" do
118
+ subject { command_class.new(linux_distro: linux_distro) }
119
+
120
+ context "when #linux_distro is :debian" do
121
+ let(:linux_distro) { :debian }
122
+
123
+ it { expect(subject.debian_linux?).to be(true) }
124
+ end
125
+
126
+ context "when #linux_distro is not :fedora" do
127
+ let(:linux_distro) { :redhat }
128
+
129
+ it { expect(subject.debian_linux?).to be(false) }
130
+ end
131
+ end
132
+
133
+ describe "#suse_linux?" do
134
+ subject { command_class.new(linux_distro: linux_distro) }
135
+
136
+ context "when #linux_distro is :suse" do
137
+ let(:linux_distro) { :suse }
138
+
139
+ it { expect(subject.suse_linux?).to be(true) }
140
+ end
141
+
142
+ context "when #linux_distro is not :suse" do
143
+ let(:linux_distro) { :debian }
144
+
145
+ it { expect(subject.suse_linux?).to be(false) }
146
+ end
147
+ end
148
+
149
+ describe "#arch_linux?" do
150
+ subject { command_class.new(linux_distro: linux_distro) }
151
+
152
+ context "when #linux_distro is :arch" do
153
+ let(:linux_distro) { :arch }
154
+
155
+ it { expect(subject.arch_linux?).to be(true) }
156
+ end
157
+
158
+ context "when #linux_distro is not :arch" do
159
+ let(:linux_distro) { :debian }
160
+
161
+ it { expect(subject.arch_linux?).to be(false) }
162
+ end
163
+ end
164
+ end
data/spec/os_spec.rb CHANGED
@@ -1,46 +1,233 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/os'
3
3
 
4
- describe OS do
5
- class TestOS
6
- include CommandKit::OS
4
+ describe CommandKit::OS do
5
+ module TestOS
6
+ class TestCommand
7
+ include CommandKit::OS
8
+ end
7
9
  end
8
10
 
9
- subject { TestOS.new }
11
+ let(:command_class) { TestOS::TestCommand }
12
+ subject { command_class.new }
13
+
14
+ describe ".os" do
15
+ subject { command_class }
10
16
 
11
- describe "#linux?" do
12
17
  context "when RUBY_PLATFORM contains 'linux'" do
13
18
  before { stub_const('RUBY_PLATFORM','x86_64-linux') }
14
19
 
15
- it { expect(subject.linux?).to be(true) }
20
+ it { expect(subject.os).to be(:linux) }
16
21
  end
17
22
 
18
- context "when RUBY_PLATFORM does not contain 'linux'" do
23
+ context "when RUBY_PLATFORM contains 'darwin'" do
19
24
  before { stub_const('RUBY_PLATFORM','aarch64-darwin') }
20
25
 
26
+ it { expect(subject.os).to be(:macos) }
27
+ end
28
+
29
+ context "when RUBY_PLATFORM contains 'freebsd'" do
30
+ before { stub_const('RUBY_PLATFORM','x86_64-freebsd') }
31
+
32
+ it { expect(subject.os).to be(:freebsd) }
33
+ end
34
+
35
+ context "when RUBY_PLATFORM contains 'openbsd'" do
36
+ before { stub_const('RUBY_PLATFORM','x86_64-openbsd') }
37
+
38
+ it { expect(subject.os).to be(:openbsd) }
39
+ end
40
+
41
+ context "when RUBY_PLATFORM contains 'netbsd'" do
42
+ before { stub_const('RUBY_PLATFORM','x86_64-netbsd') }
43
+
44
+ it { expect(subject.os).to be(:netbsd) }
45
+ end
46
+
47
+ context "when Gem.win_platform? returns true" do
48
+ before do
49
+ stub_const('RUBY_PLATFORM','x86_64-mswin')
50
+
51
+ expect(Gem).to receive(:win_platform?).and_return(true)
52
+ end
53
+
54
+ it { expect(subject.os).to be(:windows) }
55
+ end
56
+ end
57
+
58
+ describe "#initialize" do
59
+ it "must default #os to self.class.os" do
60
+ expect(subject.os).to eq(command_class.os)
61
+ end
62
+
63
+ context "when initialized with the os: keyword" do
64
+ let(:os) { :netbsd }
65
+
66
+ subject { command_class.new(os: os) }
67
+
68
+ it "must set #os" do
69
+ expect(subject.os).to eq(os)
70
+ end
71
+ end
72
+ end
73
+
74
+ describe "#linux?" do
75
+ context "when #os is :linux" do
76
+ subject { command_class.new(os: :linux) }
77
+
78
+ it { expect(subject.linux?).to be(true) }
79
+ end
80
+
81
+ context "when #os is not :linux" do
82
+ subject { command_class.new(os: :windows) }
83
+
21
84
  it { expect(subject.linux?).to be(false) }
22
85
  end
23
86
  end
24
87
 
25
88
  describe "#macos?" do
26
- context "when RUBY_PLATFORM contains 'darwin'" do
27
- before { stub_const('RUBY_PLATFORM','aarch64-darwin') }
89
+ context "when #os is :macos" do
90
+ subject { command_class.new(os: :macos) }
28
91
 
29
92
  it { expect(subject.macos?).to be(true) }
30
93
  end
31
94
 
32
- context "when RUBY_PLATFORM does not contain 'darwin'" do
33
- before { stub_const('RUBY_PLATFORM','mswin') }
95
+ context "when #os is not :macos" do
96
+ subject { command_class.new(os: :windows) }
34
97
 
35
98
  it { expect(subject.macos?).to be(false) }
36
99
  end
37
100
  end
38
101
 
102
+ describe "#freebsd?" do
103
+ context "when #os is :freebsd" do
104
+ subject { command_class.new(os: :freebsd) }
105
+
106
+ it { expect(subject.freebsd?).to be(true) }
107
+ end
108
+
109
+ context "when #os is not :freebsd" do
110
+ subject { command_class.new(os: :windows) }
111
+
112
+ it { expect(subject.freebsd?).to be(false) }
113
+ end
114
+ end
115
+
116
+ describe "#openbsd?" do
117
+ context "when #os is :openbsd" do
118
+ subject { command_class.new(os: :openbsd) }
119
+
120
+ it { expect(subject.openbsd?).to be(true) }
121
+ end
122
+
123
+ context "when #os is not :openbsd" do
124
+ subject { command_class.new(os: :windows) }
125
+
126
+ it { expect(subject.openbsd?).to be(false) }
127
+ end
128
+ end
129
+
130
+ describe "#netbsd?" do
131
+ context "when #os is :netbsd" do
132
+ subject { command_class.new(os: :netbsd) }
133
+
134
+ it { expect(subject.netbsd?).to be(true) }
135
+ end
136
+
137
+ context "when #os is not :netbsd" do
138
+ subject { command_class.new(os: :windows) }
139
+
140
+ it { expect(subject.netbsd?).to be(false) }
141
+ end
142
+ end
143
+
144
+ describe "#bsd?" do
145
+ context "when #os is :freebsd" do
146
+ subject { command_class.new(os: :freebsd) }
147
+
148
+ it { expect(subject.bsd?).to be(true) }
149
+ end
150
+
151
+ context "when #os is :openbsd" do
152
+ subject { command_class.new(os: :openbsd) }
153
+
154
+ it { expect(subject.bsd?).to be(true) }
155
+ end
156
+
157
+ context "when #os is :netbsd" do
158
+ subject { command_class.new(os: :netbsd) }
159
+
160
+ it { expect(subject.bsd?).to be(true) }
161
+ end
162
+
163
+ context "when #os is :macos" do
164
+ subject { command_class.new(os: :macos) }
165
+
166
+ it { expect(subject.bsd?).to be(false) }
167
+ end
168
+
169
+ context "when #os is :linux" do
170
+ subject { command_class.new(os: :linux) }
171
+
172
+ it { expect(subject.bsd?).to be(false) }
173
+ end
174
+
175
+ context "when #os is :windows" do
176
+ subject { command_class.new(os: :windows) }
177
+
178
+ it { expect(subject.bsd?).to be(false) }
179
+ end
180
+ end
181
+
182
+ describe "#unix?" do
183
+ context "when #os is :freebsd" do
184
+ subject { command_class.new(os: :freebsd) }
185
+
186
+ it { expect(subject.unix?).to be(true) }
187
+ end
188
+
189
+ context "when #os is :openbsd" do
190
+ subject { command_class.new(os: :openbsd) }
191
+
192
+ it { expect(subject.unix?).to be(true) }
193
+ end
194
+
195
+ context "when #os is :netbsd" do
196
+ subject { command_class.new(os: :netbsd) }
197
+
198
+ it { expect(subject.unix?).to be(true) }
199
+ end
200
+
201
+ context "when #os is :macos" do
202
+ subject { command_class.new(os: :macos) }
203
+
204
+ it { expect(subject.unix?).to be(true) }
205
+ end
206
+
207
+ context "when #os is :linux" do
208
+ subject { command_class.new(os: :linux) }
209
+
210
+ it { expect(subject.unix?).to be(true) }
211
+ end
212
+
213
+ context "when #os is :windows" do
214
+ subject { command_class.new(os: :windows) }
215
+
216
+ it { expect(subject.unix?).to be(false) }
217
+ end
218
+ end
219
+
39
220
  describe "#windows?" do
40
- it "must call Gem.win_platform?" do
41
- expect(Gem).to receive(:win_platform?)
221
+ context "when #os is :windows" do
222
+ subject { command_class.new(os: :windows) }
223
+
224
+ it { expect(subject.windows?).to be(true) }
225
+ end
226
+
227
+ context "when #os is not :windows" do
228
+ subject { command_class.new(os: :linux) }
42
229
 
43
- subject.windows?
230
+ it { expect(subject.windows?).to be(false) }
44
231
  end
45
232
  end
46
233
  end