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 +4 -4
- data/README.md +16 -17
- data/bin/can +1 -1
- data/can.gemspec +15 -15
- data/lib/can/argparse.rb +3 -3
- data/lib/{empty.rb → can/empty.rb} +1 -1
- data/lib/{info.rb → can/info.rb} +2 -5
- data/lib/{list.rb → can/list.rb} +4 -4
- data/lib/{trash.rb → can/trash.rb} +2 -2
- data/lib/{untrash.rb → can/untrash.rb} +1 -2
- data/lib/can/version.rb +1 -1
- data/lib/can.rb +13 -8
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dbd9171ffb0acfa035abd758884336a5b7e716b56b5c80692ae3a490c1e7673
|
4
|
+
data.tar.gz: d960d2e4d646b2297b9ba98750d4004c303033f6541ae90e8c3a02602fc35a2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
27
|
-
`can foo.txt bar.txt`
|
25
|
+
Trash files
|
26
|
+
: `can foo.txt bar.txt`
|
28
27
|
|
29
|
-
|
30
|
-
`can -r foo.txt bar.d`
|
28
|
+
Trash directories and files
|
29
|
+
: `can -r foo.txt bar.d`
|
31
30
|
|
32
|
-
|
33
|
-
`can -l`
|
31
|
+
List files in trashcan
|
32
|
+
: `can -l`
|
34
33
|
|
35
|
-
|
36
|
-
`can -l '^foo'`
|
34
|
+
List files in trashcan that match a regex
|
35
|
+
: `can -l '^foo'`
|
37
36
|
|
38
|
-
|
39
|
-
`can -n foo.txt bar.d`
|
37
|
+
View trashinfo of files
|
38
|
+
: `can -n foo.txt bar.d`
|
40
39
|
|
41
|
-
|
42
|
-
`can -u foo.txt bar.d`
|
40
|
+
Untrash files
|
41
|
+
: `can -u foo.txt bar.d`
|
43
42
|
|
44
|
-
|
45
|
-
`can -e foo.txt bar.d`
|
43
|
+
Empty files from trashcan**
|
44
|
+
: `can -e foo.txt bar.d`
|
46
45
|
|
47
|
-
|
48
|
-
`can -e`
|
46
|
+
Empty entire trashcan
|
47
|
+
: `can -e`
|
data/bin/can
CHANGED
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
10
|
+
@argv.each do |filename|
|
11
11
|
trashinfo_filename = "#{filename}.trashinfo"
|
12
12
|
|
13
13
|
file_path = File.join(HOME_TRASH_FILES_DIRECTORY, filename)
|
data/lib/{info.rb → can/info.rb}
RENAMED
@@ -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
|
7
|
+
if @argv.empty?
|
11
8
|
Error.fatal 'missing operand'
|
12
9
|
else
|
13
|
-
|
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
|
|
data/lib/{list.rb → can/list.rb}
RENAMED
@@ -3,13 +3,13 @@
|
|
3
3
|
module Can
|
4
4
|
def self.list
|
5
5
|
# Given no args, show every trashed file
|
6
|
-
if
|
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
|
12
|
-
regex = Regexp.new(
|
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 #{
|
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
|
26
|
+
Error.fatal 'missing operand' if @argv.empty? && !@options.include?(:force)
|
27
27
|
|
28
|
-
|
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
|
-
|
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
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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.
|
29
|
-
|
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.
|
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-
|
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
|