can_cli 0.1.8 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d045fc55d52033bff2f1545671627292f4c9cfc31577d6895c1eecf92b023a4
4
- data.tar.gz: 5e64a110561d1772c9655c69abe168258555265f2c85ed25d3e13de52f20ae9a
3
+ metadata.gz: 9dbd9171ffb0acfa035abd758884336a5b7e716b56b5c80692ae3a490c1e7673
4
+ data.tar.gz: d960d2e4d646b2297b9ba98750d4004c303033f6541ae90e8c3a02602fc35a2e
5
5
  SHA512:
6
- metadata.gz: d116038236f64812a1f6ffd1039b2212cd6d0636277be91c7b2a85ee903a1adb8a7c6a70ac16abe3643f627566955b0bcd4daa4d8a4382bbe916fecd3ca31d1b
7
- data.tar.gz: c6641f08b8e26caebe3d83634875597d358edb86d3b3612b6eb4d6f8dfcad54d7830dd4fdecc86239771c6f9f4185a591ab8fa3cb5dadc36426d10a78f1548a3
6
+ metadata.gz: e38eece364cbc9d16a67347aeac363239e1f4351158d9b228bd2553f3de57033e749a4517aaadb01c9a811df29968fa938b4707d067b72d8fb393d5a1b39445b
7
+ data.tar.gz: c740ebaed2650dfd6770b34fb3f87686aba7ceef378c175de2caba28f02acc5a24c716031fbfd96f3471502d5bcd3c15a22440a5f0fde5aa6e2fe5df1a988b70
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
  <h1 style="text-align: center;">can</h1>
2
- -----------------------------
3
2
 
4
3
  A command line implementation of the [Freedesktop XDG trash
5
4
  specification](https://specifications.freedesktop.org/trash-spec/trashspec-latest.html).
@@ -23,26 +22,26 @@ Install on AUR:
23
22
 
24
23
  **Does not cover all options**
25
24
 
26
- **Trash files**
27
- `can foo.txt bar.txt`
25
+ Trash files
26
+ : `can foo.txt bar.txt`
28
27
 
29
- **Trash directories and files**
30
- `can -r foo.txt bar.d`
28
+ Trash directories and files
29
+ : `can -r foo.txt bar.d`
31
30
 
32
- **List files in trashcan**
33
- `can -l`
31
+ List files in trashcan
32
+ : `can -l`
34
33
 
35
- **List files in trashcan that match a regex**
36
- `can -l '^foo'`
34
+ List files in trashcan that match a regex
35
+ : `can -l '^foo'`
37
36
 
38
- **View trashinfo of files**
39
- `can -n foo.txt bar.d`
37
+ View trashinfo of files
38
+ : `can -n foo.txt bar.d`
40
39
 
41
- **Untrash files**
42
- `can -u foo.txt bar.d`
40
+ Untrash files
41
+ : `can -u foo.txt bar.d`
43
42
 
44
- **Empty files from trashcan**
45
- `can -e foo.txt bar.d`
43
+ Empty files from trashcan**
44
+ : `can -e foo.txt bar.d`
46
45
 
47
- **Empty entire trashcan**
48
- `can -e`
46
+ Empty entire trashcan
47
+ : `can -e`
data/bin/can CHANGED
@@ -3,4 +3,4 @@
3
3
 
4
4
  require 'can'
5
5
 
6
- Can.can
6
+ Can.cli
data/can.gemspec CHANGED
@@ -10,21 +10,21 @@ Gem::Specification.new do |s|
10
10
  s.description = 'A command-line trashcan interface implementing the FreeDesktop trash specification as a drop-in replacement for rm.'
11
11
  s.authors = ['Sawyer Shepherd']
12
12
  s.email = 'contact@sawyershepherd.org'
13
- s.files = [
14
- 'LICENSE',
15
- 'README.md',
16
- 'bin/can',
17
- 'can.gemspec',
18
- 'lib/can/argparse.rb',
19
- 'lib/can/version.rb',
20
- 'lib/can.rb',
21
- 'lib/empty.rb',
22
- 'lib/error.rb',
23
- 'lib/info.rb',
24
- 'lib/list.rb',
25
- 'lib/trash.rb',
26
- 'lib/trashinfo.rb',
27
- 'lib/untrash.rb'
13
+ s.files = %w[
14
+ LICENSE
15
+ README.md
16
+ bin/can
17
+ can.gemspec
18
+ lib/can.rb
19
+ lib/can/argparse.rb
20
+ lib/can/empty.rb
21
+ lib/can/info.rb
22
+ lib/can/list.rb
23
+ lib/can/trash.rb
24
+ lib/can/untrash.rb
25
+ lib/can/version.rb
26
+ lib/error.rb
27
+ lib/trashinfo.rb
28
28
  ]
29
29
  s.homepage = 'https://github.com/sawshep/can'
30
30
  s.license = 'GPL-3.0'
data/lib/can/argparse.rb CHANGED
@@ -40,7 +40,7 @@ module Can
40
40
 
41
41
  module ArgParse
42
42
  Version = VERSION
43
- def self.init_args
43
+ def self.init_args(argv)
44
44
  options = Set.new
45
45
 
46
46
  OptionParser.new do |opts|
@@ -51,11 +51,11 @@ module Can
51
51
  options << mode
52
52
  end
53
53
  end
54
- end.parse!
54
+ end.parse!(argv)
55
55
 
56
56
  Error.fatal 'Too many mode arguments' if ArgParse.incompatible_opts?(options)
57
57
 
58
- options
58
+ return options, argv
59
59
  end
60
60
 
61
61
  # Sees if options has incompatible items
@@ -7,7 +7,7 @@ module Can
7
7
  FileUtils.rm_r Dir.glob("#{HOME_TRASH_INFO_DIRECTORY}/*"), secure: true
8
8
  FileUtils.rm_r Dir.glob("#{HOME_TRASH_FILES_DIRECTORY}/*"), secure: true
9
9
  else
10
- ARGV.each do |filename|
10
+ @argv.each do |filename|
11
11
  trashinfo_filename = "#{filename}.trashinfo"
12
12
 
13
13
  file_path = File.join(HOME_TRASH_FILES_DIRECTORY, filename)
@@ -1,16 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Can
4
- # TODO: Parse the .trashinfo files to make them more human
5
- # readable. Also, display the filename above the information
6
- # with empty lines between consecutive info blocks.
7
4
  def self.info
8
5
  # Fails with a fatal error even with --force, intended
9
6
  # behavior.
10
- if ARGV.empty?
7
+ if @argv.empty?
11
8
  Error.fatal 'missing operand'
12
9
  else
13
- ARGV.each_with_index do |file, i|
10
+ @argv.each_with_index do |file, i|
14
11
  trashinfo_filename = "#{file}.trashinfo"
15
12
  trashinfo_path = File.join(HOME_TRASH_INFO_DIRECTORY, trashinfo_filename)
16
13
 
@@ -3,13 +3,13 @@
3
3
  module Can
4
4
  def self.list
5
5
  # Given no args, show every trashed file
6
- if ARGV.empty?
6
+ if @argv.empty?
7
7
  puts Dir.children(HOME_TRASH_FILES_DIRECTORY)
8
8
 
9
9
  # Given a regex pattern as an arg, print trashed files
10
10
  # that fit
11
- elsif ARGV.length == 1
12
- regex = Regexp.new(ARGV[0])
11
+ elsif @argv.length == 1
12
+ regex = Regexp.new(@argv[0])
13
13
  puts(
14
14
  Dir.children(HOME_TRASH_FILES_DIRECTORY).select do |file|
15
15
  regex =~ file
@@ -17,7 +17,7 @@ module Can
17
17
  )
18
18
 
19
19
  else
20
- raise StandardError, "can: mode --list expects 0 to 1 arguments, given #{ARGV.length}"
20
+ raise StandardError, "can: mode --list expects 0 to 1 arguments, given #{@argv.length}"
21
21
  end
22
22
  end
23
23
  end
@@ -23,9 +23,9 @@ end
23
23
 
24
24
  module Can
25
25
  def self.trash
26
- Error.fatal 'missing operand' if ARGV.empty? && !@options.include?(:force)
26
+ Error.fatal 'missing operand' if @argv.empty? && !@options.include?(:force)
27
27
 
28
- ARGV.each do |path|
28
+ @argv.each do |path|
29
29
  # TODO: If both `-f` and `-i` are used, can should
30
30
  # prompt if `-i` is used last. If `-f` is used last,
31
31
  # can should not prompt trashings. This follows the
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Can
4
4
  def self.untrash
5
- ARGV.each do |filename|
5
+ @argv.each do |filename|
6
6
  file_path = File.join(HOME_TRASH_FILES_DIRECTORY, filename)
7
7
 
8
8
  unless File.exist? file_path
@@ -18,7 +18,6 @@ module Can
18
18
 
19
19
  original_path = trashinfo[:path]
20
20
 
21
- # TODO: Implement more thorough error handling
22
21
  if File.exist? original_path
23
22
  Error.nonfatal "cannot untrash '#{filename}' to '#{original_path}': File exists"
24
23
  next
data/lib/can/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Can
4
- VERSION = '0.1.8'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/can.rb CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  require 'fileutils'
4
4
 
5
- require 'can/argparse'
6
5
  require 'trashinfo'
7
6
  require 'error'
8
7
 
9
- require_relative 'empty'
10
- require_relative 'info'
11
- require_relative 'list'
12
- require_relative 'untrash'
13
- require_relative 'trash'
8
+ require 'can/argparse'
9
+ require 'can/empty'
10
+ require 'can/info'
11
+ require 'can/list'
12
+ require 'can/untrash'
13
+ require 'can/trash'
14
14
 
15
15
  module Can
16
16
  XDG_DATA_HOME_DEFAULT = File.join(ENV['HOME'], '.local/share')
@@ -25,8 +25,13 @@ module Can
25
25
  FileUtils.mkpath HOME_TRASH_INFO_DIRECTORY
26
26
  end
27
27
 
28
- def self.can
29
- @options = ArgParse.init_args
28
+ def self.cli
29
+ can ARGV
30
+ end
31
+
32
+
33
+ def self.can(argv)
34
+ @options, @argv = ArgParse.init_args(argv)
30
35
 
31
36
  mode = ArgParse.mode @options
32
37
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: can_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sawyer Shepherd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-19 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -38,14 +38,14 @@ files:
38
38
  - can.gemspec
39
39
  - lib/can.rb
40
40
  - lib/can/argparse.rb
41
+ - lib/can/empty.rb
42
+ - lib/can/info.rb
43
+ - lib/can/list.rb
44
+ - lib/can/trash.rb
45
+ - lib/can/untrash.rb
41
46
  - lib/can/version.rb
42
- - lib/empty.rb
43
47
  - lib/error.rb
44
- - lib/info.rb
45
- - lib/list.rb
46
- - lib/trash.rb
47
48
  - lib/trashinfo.rb
48
- - lib/untrash.rb
49
49
  homepage: https://github.com/sawshep/can
50
50
  licenses:
51
51
  - GPL-3.0