minitar-cli 0.6

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.
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The command dispatcher for Minitar::CLI. This will be replaced in a future
4
+ # version by one of the better-executed CLI application frameworks like GLI,
5
+ # after Ruby 1.8 and 1.9 support have been dropped.
6
+ class Minitar::CLI::Commander
7
+ attr_reader :commands
8
+ attr_reader :default_command
9
+ attr_reader :ioe
10
+
11
+ def initialize(ioe)
12
+ @ioe = default_ioe(ioe)
13
+ @commands = {}
14
+ @default_command = nil
15
+ end
16
+
17
+ def register(command)
18
+ command = command.new(self) if command.kind_of?(Class)
19
+ raise CommandAlreadyExists if command.commander != self
20
+ raise CommandAlreadyExists if command?(command.name)
21
+
22
+ commands[command.name] = command
23
+
24
+ # rubocop:disable Style/GuardClause
25
+ if command.respond_to?(:altname)
26
+ commands[command.altname] = command unless command?(command.altname)
27
+ end
28
+ # rubocop:enable Style/GuardClause
29
+ end
30
+
31
+ def default_command=(command)
32
+ command = command.new if command.kind_of?(Class)
33
+
34
+ @default_command =
35
+ if command.kind_of?(Minitar::CLI::Command)
36
+ register(command) unless command?(command.name)
37
+ command
38
+ elsif command?(command)
39
+ commands[command]
40
+ else
41
+ raise UnknownCommandError
42
+ end
43
+ end
44
+
45
+ def command?(command)
46
+ commands.key?(command)
47
+ end
48
+
49
+ def command(command)
50
+ if command?(command)
51
+ commands[command]
52
+ else
53
+ default_command
54
+ end
55
+ end
56
+ alias [] command
57
+
58
+ def default_ioe(ioe = {})
59
+ ioe[:input] ||= $stdin
60
+ ioe[:output] ||= $stdout
61
+ ioe[:error] ||= $stderr
62
+ ioe
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+
3
+ require 'fileutils'
4
+ require 'minitar'
5
+
6
+ gem 'minitest'
7
+ require 'minitest/autorun'
8
+
9
+ Dir.glob(File.join(File.dirname(__FILE__), 'support/*.rb')).each do |support|
10
+ require support
11
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitar/cli'
4
+
5
+ module MinitarCLITestHelper
6
+ def cli(*args)
7
+ Minitar::CLI.run(args)
8
+ end
9
+
10
+ def r(*r)
11
+ Regexp.union(*r)
12
+ end
13
+
14
+ Minitest::Test.send(:include, self)
15
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest_helper'
4
+
5
+ class TestCLIHelp < Minitest::Test
6
+ def test_help_output_with_no_args
7
+ assert_output Minitar::CLI::Command::Help::BASIC do
8
+ assert_equal 0, cli
9
+ end
10
+ end
11
+
12
+ def test_help_output_with_help
13
+ assert_output Minitar::CLI::Command::Help::BASIC do
14
+ assert_equal 0, cli('help')
15
+ end
16
+ end
17
+
18
+ def test_help_output_with_bad_command
19
+ assert_output Minitar::CLI::Command::Help::BASIC do
20
+ assert_equal 0, cli('foo')
21
+ end
22
+ end
23
+
24
+ def test_help_output_with_help_bad_command
25
+ assert_output "Unknown command: foo\n#{Minitar::CLI::Command::Help::BASIC}" do
26
+ assert_equal 0, cli('help', 'foo')
27
+ end
28
+ end
29
+
30
+ def test_help_output_commands
31
+ assert_output Minitar::CLI::Command::Help::COMMANDS do
32
+ assert_equal 0, cli('help', 'commands')
33
+ end
34
+ end
35
+
36
+ def test_help_output_create
37
+ assert_output Minitar::CLI::Command::Create::HELP do
38
+ assert_equal 0, cli('help', 'create')
39
+ end
40
+ end
41
+
42
+ def test_help_output_create_minargs
43
+ assert_output "Not enough arguments.\n\n#{Minitar::CLI::Command::Create::HELP}" do
44
+ assert_equal 255, cli('create')
45
+ end
46
+ end
47
+
48
+ def test_help_output_list
49
+ assert_output Minitar::CLI::Command::List::HELP do
50
+ assert_equal 0, cli('help', 'list')
51
+ end
52
+ end
53
+
54
+ def test_help_output_list_minargs
55
+ assert_output "Not enough arguments.\n\n#{Minitar::CLI::Command::List::HELP}" do
56
+ assert_equal 255, cli('list')
57
+ end
58
+ end
59
+
60
+ def test_help_output_extract
61
+ assert_output Minitar::CLI::Command::Extract::HELP do
62
+ assert_equal 0, cli('help', 'extract')
63
+ end
64
+ end
65
+
66
+ def test_help_output_extract_minargs
67
+ assert_output "Not enough arguments.\n\n#{Minitar::CLI::Command::Extract::HELP}" do
68
+ assert_equal 255, cli('extract')
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TestCLIList < Minitest::Test
4
+ def list_bad_dir(args = [])
5
+ cli_list('bad-dir', args)
6
+ end
7
+
8
+ def list_spaces(args = [])
9
+ cli_list('spaces', args)
10
+ end
11
+
12
+ def cli_list(name, args = [])
13
+ args = %W(list test/fixtures/#{name}.tar.gz) + Array(args)
14
+ cli(*args)
15
+ end
16
+
17
+ def test_list_output_bad_dir_fixture
18
+ assert_output "../qwerty\n" do
19
+ assert_equal 0, list_bad_dir
20
+ end
21
+ end
22
+
23
+ def test_list_output_spaces
24
+ assert_output r([ %r{\A\./$}, %r{^\./bin/minitar\n\z} ]) do
25
+ assert_equal 0, list_spaces
26
+ end
27
+ end
28
+
29
+ def test_list_output_spaces_verbose
30
+ patterns = [
31
+ %r{\Adrwxr-xr-x\s+0\s+austin\s+staff\s+0 Feb 0[67] \d{2}:24 \./$},
32
+ %r{^-rwxr-xr-x\s+0\s+austin\s+staff\s+219 Feb 0[67] \d{2}:29 \./bin/minitar\n\z}
33
+ ]
34
+ assert_output r(patterns) do
35
+ assert_equal 0, list_spaces('--verbose')
36
+ end
37
+ end
38
+
39
+ def test_list_output_spaces_verbose_sort_size
40
+ patterns = [
41
+ %r{\Adrwxr-xr-x\s+0\s+austin\s+staff\s+0 Feb 0[67] \d{2}:24 \./$},
42
+ %r{^-rw-r--r--\s+8\s+austin\s+staff\s+4296 Feb 0[67] \d{2}:29 ./lib/minitar/cli/command/extract.rb\n\z}
43
+ ]
44
+ assert_output r(patterns) do
45
+ assert_equal 0, list_spaces(%w(--verbose --sort size))
46
+ end
47
+ end
48
+
49
+ def test_list_output_spaces_verbose_sort_size_reverse
50
+ patterns = [
51
+ %r{\A-rw-r--r--\s+8\s+austin\s+staff\s+4296 Feb 0[67] \d{2}:29 ./lib/minitar/cli/command/extract.rb$},
52
+ %r{^drwxr-xr-x\s+0\s+austin\s+staff\s+0 Feb 0[67] \d{2}:24 \./\n\z}
53
+ ]
54
+
55
+ assert_output r(patterns) do
56
+ assert_equal 0, list_spaces(%w(--verbose --sort size --reverse))
57
+ end
58
+ end
59
+
60
+ def test_list_output_spaces_verbose_sort_name
61
+ patterns = [
62
+ %r{\Adrwxr-xr-x\s+0\s+austin\s+staff\s+0 Feb 0[67] \d{2}:24 \./$},
63
+ %r{^-rw-r--r--\s+8\s+austin\s+staff\s+3974 Feb 0[67] \d{2}:29 ./minitar-cli.gemspec\n\z}
64
+ ]
65
+ assert_output r(patterns) do
66
+ assert_equal 0, list_spaces(%w(--verbose --sort name))
67
+ end
68
+ end
69
+
70
+ def test_list_output_spaces_verbose_sort_name_reverse
71
+ patterns = [
72
+ %r{\A-rw-r--r--\s+8\s+austin\s+staff\s+3974 Feb 0[67] \d{2}:29 ./minitar-cli.gemspec$},
73
+ %r{^drwxr-xr-x\s+0\s+austin\s+staff\s+0 Feb 0[67] \d{2}:24 \./\n\z}
74
+ ]
75
+
76
+ assert_output r(patterns) do
77
+ assert_equal 0, list_spaces(%w(--verbose --sort name --reverse))
78
+ end
79
+ end
80
+
81
+ def test_list_output_spaces_verbose_sort_mtime
82
+ patterns = [
83
+ %r{\Adrwxr-xr-x\s+0\s+austin\s+staff\s+0 Nov 0[23] \d{2}:43 \./docs/$},
84
+ %r{^-rw-r--r--\s+8\s+austin\s+staff\s+4296 Feb 0[67] \d{2}:29 ./.pullreview.yml\n\z}
85
+ ]
86
+ assert_output r(patterns) do
87
+ assert_equal 0, list_spaces(%w(--verbose --sort mtime))
88
+ end
89
+ end
90
+
91
+ def test_list_output_spaces_verbose_sort_mtime_reverse
92
+ patterns = [
93
+ %r{\A-rw-r--r--\s+8\s+austin\s+staff\s+4296 Feb 0[67] \d{2}:29 ./.pullreview.yml$},
94
+ %r{^drwxr-xr-x\s+0\s+austin\s+staff\s+0 Nov 0[23] \d{2}:43 \./docs/\n\z}
95
+ ]
96
+
97
+ assert_output r(patterns) do
98
+ assert_equal 0, list_spaces(%w(--verbose --sort mtime --reverse))
99
+ end
100
+ end
101
+
102
+ def test_list_stdin
103
+ assert_output "../qwerty\n" do
104
+ File.open('test/fixtures/bad-dir.tar.gz') do |f|
105
+ assert_equal 0, Minitar::CLI.run(%w(list - --uncompress), f)
106
+ end
107
+ end
108
+ end
109
+
110
+ def test_list_output_spaces_filtered
111
+ assert_output "./bin/minitar\n" do
112
+ assert_equal 0, list_spaces('./bin/minitar')
113
+ end
114
+ end
115
+
116
+ def test_list_output_spaces_filtered_verbose
117
+ expected =
118
+ %r{\A-rwxr-xr-x\s+0\s+austin\s+staff\s+219 Feb 0[67] \d{2}:29 ./bin/minitar\n\z}
119
+ assert_output expected do
120
+ assert_equal 0, list_spaces(['./bin/minitar', '--verbose'])
121
+ end
122
+ end
123
+ end
metadata ADDED
@@ -0,0 +1,265 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitar-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.6'
5
+ platform: ruby
6
+ authors:
7
+ - Austin Ziegler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: powerbar
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe-doofus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hoe-gemspec2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hoe-git
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: hoe-rubygems
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: hoe-travis
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: minitest-autotest
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ - - "<"
133
+ - !ruby/object:Gem::Version
134
+ version: '2'
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '1.0'
142
+ - - "<"
143
+ - !ruby/object:Gem::Version
144
+ version: '2'
145
+ - !ruby/object:Gem::Dependency
146
+ name: rake
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '10.0'
152
+ - - "<"
153
+ - !ruby/object:Gem::Version
154
+ version: '12'
155
+ type: :development
156
+ prerelease: false
157
+ version_requirements: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '10.0'
162
+ - - "<"
163
+ - !ruby/object:Gem::Version
164
+ version: '12'
165
+ - !ruby/object:Gem::Dependency
166
+ name: rdoc
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0.0'
172
+ type: :development
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0.0'
179
+ - !ruby/object:Gem::Dependency
180
+ name: hoe
181
+ requirement: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - "~>"
184
+ - !ruby/object:Gem::Version
185
+ version: '3.16'
186
+ type: :development
187
+ prerelease: false
188
+ version_requirements: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - "~>"
191
+ - !ruby/object:Gem::Version
192
+ version: '3.16'
193
+ description: |-
194
+ <tt>minitar-cli</tt> is a pure-Ruby command-line tool that uses
195
+ {minitar}[https://github.com/halostatue/minitar] to provide a command-line
196
+ tool, +minitar+, for working with POSIX tar(1) archive files.
197
+
198
+ This is release 0.6, extracted from {minitar}[https://halostatue.ca/minitar],
199
+ with modernizations.
200
+ email:
201
+ - halostatue@gmail.com
202
+ executables:
203
+ - minitar
204
+ extensions: []
205
+ extra_rdoc_files:
206
+ - Contributing.md
207
+ - History.md
208
+ - Licence.md
209
+ - Manifest.txt
210
+ - README.rdoc
211
+ - docs/bsdl.txt
212
+ - docs/ruby.txt
213
+ files:
214
+ - Contributing.md
215
+ - History.md
216
+ - Licence.md
217
+ - Manifest.txt
218
+ - README.rdoc
219
+ - Rakefile
220
+ - bin/minitar
221
+ - docs/bsdl.txt
222
+ - docs/ruby.txt
223
+ - lib/minitar/cli.rb
224
+ - lib/minitar/cli/command.rb
225
+ - lib/minitar/cli/command/create.rb
226
+ - lib/minitar/cli/command/extract.rb
227
+ - lib/minitar/cli/command/help.rb
228
+ - lib/minitar/cli/command/list.rb
229
+ - lib/minitar/cli/commander.rb
230
+ - test/fixtures/bad-dir.tar.gz
231
+ - test/fixtures/spaces.tar.gz
232
+ - test/minitest_helper.rb
233
+ - test/support/minitar_cli_test_helper.rb
234
+ - test/test_cli_help.rb
235
+ - test/test_cli_list.rb
236
+ homepage: https://github.com/halostatue/minitar-cli/
237
+ licenses:
238
+ - Ruby
239
+ - BSD-2-Clause
240
+ metadata: {}
241
+ post_install_message:
242
+ rdoc_options:
243
+ - "--main"
244
+ - README.rdoc
245
+ require_paths:
246
+ - lib
247
+ required_ruby_version: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - ">="
250
+ - !ruby/object:Gem::Version
251
+ version: '1.8'
252
+ required_rubygems_version: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - ">="
255
+ - !ruby/object:Gem::Version
256
+ version: '0'
257
+ requirements: []
258
+ rubyforge_project:
259
+ rubygems_version: 2.5.1
260
+ signing_key:
261
+ specification_version: 4
262
+ summary: "<tt>minitar-cli</tt> is a pure-Ruby command-line tool that uses {minitar}[https://github.com/halostatue/minitar]
263
+ to provide a command-line tool, +minitar+, for working with POSIX tar(1) archive
264
+ files"
265
+ test_files: []