excavate 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9ac901b1d15ed4e916d2e76c0b902070918d518169f177fdf338df564a002e4
4
- data.tar.gz: f3d5f8d33256c59bd63d3d517e66ab46eda8cf1e02f3d26a732add451e8d92a7
3
+ metadata.gz: '05638165852fcf0b41aa72e491d285182a11d2b5989cdee78393ff3f8719a017'
4
+ data.tar.gz: b3a9e906c6dd35274e0e2b7a7e90f5c10ea8447b0f77c0b0cd59b277d224c06d
5
5
  SHA512:
6
- metadata.gz: 2e9dcda07eec36ef7c4dbcced2927e26ad2b4daff57f3544a79aeac7c5a4da4fb44fd3d16e5868ae17387614ea549838aa61565fd283d19036e6aa0e02f8e54a
7
- data.tar.gz: 9fd35d2d181083bf78a5c4250fb9ee22ff925f8b9d5964243f2d1f810f90dc04183973c9ff0d1c7c778879512e70749a5757ac4b9d81029e2b5a56331ba35c12
6
+ metadata.gz: 3eea36c08d18780f9131875d3ca78c33bdf558c957425d9b936f08eb1512bb298724f68f418edb3b3db0c941e228e11473826ad6a16b6fcf399935f73be03514
7
+ data.tar.gz: 371061bead10a3716b931a9877153c3ea47e8666030fbb0dc7885217da32428f7f43298ec0a98a7fc0f2ef2ffd7a51af5e7371eedbee06f19d34b7a5995b8e3d
data/README.adoc CHANGED
@@ -33,21 +33,38 @@ To extract an archive containing other archives inside:
33
33
 
34
34
  [source,ruby]
35
35
  ----
36
- archive = "path/to/archive.cab"
37
36
  target = Dir.mktmpdir
38
- Excavate::Archive.new(archive).extract(target, recursive_packages: true)
37
+ Excavate::Archive.new("path/to/archive.cab").extract(target, recursive_packages: true)
39
38
  ----
40
39
 
41
40
  The same but allowing to choose only necessary files inside:
42
41
 
43
42
  [source,ruby]
44
43
  ----
44
+ target = Dir.mktmpdir
45
45
  Excavate::Archive.new("path/to/archive.cab").files(recursive_packages: true) do |path|
46
- FileUtils.mv(path, Dir.mktmpdir) if path.end_with?(".txt")
46
+ FileUtils.mv(path, target) if path.end_with?(".txt")
47
47
  end
48
48
  ----
49
49
 
50
50
 
51
+ == CLI
52
+
53
+ `excavate` can be used via command line. To extract an archive including the nested ones:
54
+
55
+ [source,sh]
56
+ ----
57
+ $ excavate --recursive path/to/archive.cab
58
+ ----
59
+
60
+ If you'd like to skip extraction of nested archives, just use:
61
+
62
+ [source,sh]
63
+ ----
64
+ $ excavate path/to/archive.cab
65
+ ----
66
+
67
+
51
68
  == Development
52
69
 
53
70
  We are following Sandi Metz's Rules for this gem, you can read the
data/excavate.gemspec CHANGED
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_runtime_dependency "ruby-ole", "~> 1.0"
32
32
  spec.add_runtime_dependency "rubyzip", "~> 2.3"
33
33
  spec.add_runtime_dependency "seven_zip_ruby", "~> 1.0"
34
+ spec.add_runtime_dependency "thor", "~> 1.0"
34
35
  end
data/exe/excavate ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "excavate/cli"
5
+
6
+ status_code = Excavate::CLI.start
7
+ exit status_code.is_a?(Integer) ? status_code : 1
data/lib/excavate.rb CHANGED
@@ -9,4 +9,6 @@ require_relative "excavate/utils"
9
9
  module Excavate
10
10
  class Error < StandardError; end
11
11
  class UnknownArchiveError < Error; end
12
+ class TargetExistsError < Error; end
13
+ class TargetNotEmptyError < Error; end
12
14
  end
@@ -24,16 +24,31 @@ module Excavate
24
24
  FileUtils.rm_rf(target)
25
25
  end
26
26
 
27
- def extract(target, recursive_packages: false)
27
+ def extract(target = nil, recursive_packages: false)
28
+ source = File.expand_path(@archive)
29
+ target ||= default_target(source)
30
+ raise(TargetNotEmptyError, "Target directory `#{File.basename(target)}` is not empty.") unless Dir.empty?(target)
31
+
28
32
  if recursive_packages
29
- extract_recursively(@archive, target)
33
+ extract_recursively(source, target)
30
34
  else
31
- extract_once(@archive, target)
35
+ extract_once(source, target)
32
36
  end
37
+
38
+ target
33
39
  end
34
40
 
35
41
  private
36
42
 
43
+ def default_target(source)
44
+ target = File.expand_path(File.basename(source, ".*"))
45
+ raise(TargetExistsError, "Target directory `#{File.basename(target)}` already exists.") if File.exist?(target)
46
+
47
+ FileUtils.mkdir(target)
48
+
49
+ target
50
+ end
51
+
37
52
  def extract_recursively(archive, target)
38
53
  extract_once(archive, target)
39
54
 
@@ -0,0 +1,50 @@
1
+ require "thor"
2
+
3
+ require_relative "../excavate"
4
+
5
+ module Excavate
6
+ class CLI < Thor
7
+ STATUS_SUCCESS = 0
8
+ STATUS_UNKNOWN_ERROR = 1
9
+ STATUS_TARGET_EXISTS = 2
10
+ STATUS_TARGET_NOT_EMPTY = 3
11
+
12
+ def self.exit_on_failure?
13
+ false
14
+ end
15
+
16
+ def self.start(given_args = ARGV, config = {})
17
+ args = if all_commands.key?(given_args[0])
18
+ given_args
19
+ else
20
+ given_args.dup.unshift("extract")
21
+ end
22
+
23
+ super(args, config)
24
+ end
25
+
26
+ desc "extract ARCHIVE", "Extract ARCHIVE to a new directory"
27
+ option :recursive, aliases: :r, type: :boolean, default: false, desc: "Also extract all nested archives."
28
+ def extract(archive)
29
+ target = Excavate::Archive.new(archive).extract(recursive_packages: options[:recursive])
30
+ success("Successfully extracted to #{File.basename(target)}/")
31
+ rescue TargetExistsError => e
32
+ error(e.message, STATUS_TARGET_EXISTS)
33
+ rescue TargetNotEmptyError => e
34
+ error(e.message, STATUS_TARGET_NOT_EMPTY)
35
+ end
36
+ default_task :extract
37
+
38
+ private
39
+
40
+ def success(message)
41
+ say(message)
42
+ STATUS_SUCCESS
43
+ end
44
+
45
+ def error(message, status)
46
+ say(message, :red)
47
+ status
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Excavate
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excavate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-26 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: arr-pm
@@ -80,10 +80,25 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
83
97
  description: Extract nested archives with a single command.
84
98
  email:
85
99
  - open.source@ribose.com
86
- executables: []
100
+ executables:
101
+ - excavate
87
102
  extensions: []
88
103
  extra_rdoc_files: []
89
104
  files:
@@ -97,8 +112,10 @@ files:
97
112
  - README.adoc
98
113
  - Rakefile
99
114
  - excavate.gemspec
115
+ - exe/excavate
100
116
  - lib/excavate.rb
101
117
  - lib/excavate/archive.rb
118
+ - lib/excavate/cli.rb
102
119
  - lib/excavate/extractors.rb
103
120
  - lib/excavate/extractors/cab_extractor.rb
104
121
  - lib/excavate/extractors/cpio/cpio.rb
@@ -121,7 +138,7 @@ metadata:
121
138
  homepage_uri: https://github.com/fontist/excavate
122
139
  source_code_uri: https://github.com/fontist/excavate
123
140
  changelog_uri: https://github.com/fontist/excavate
124
- post_install_message:
141
+ post_install_message:
125
142
  rdoc_options: []
126
143
  require_paths:
127
144
  - lib
@@ -137,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
154
  version: '0'
138
155
  requirements: []
139
156
  rubygems_version: 3.0.3
140
- signing_key:
157
+ signing_key:
141
158
  specification_version: 4
142
159
  summary: Extract nested archives with a single command.
143
160
  test_files: []