dirfy 0.2.1 → 0.3.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/lib/dirfy/cli.rb +10 -1
- data/lib/dirfy/parser.rb +16 -4
- data/lib/dirfy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8e6bf9d28ac3108a8de6bc541c8c0e2b63fdd101bcf973bcbad6369d87b6dc5
|
|
4
|
+
data.tar.gz: 0e925d19a257eeb53d9ab97f826056cd0c063bd7ec44ef44242aea30dec3b24f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7d51b837da07c76434ff5d81ecc91e497cbd1360bcc3de28eff299c95489d43d8a6d1fd95331f4b7d892ddb5e3ba861b2c553373d38c08a9ee174fccdbb4bff7
|
|
7
|
+
data.tar.gz: e6d08d7060cd432e3dd73b3b1c1a6a649406820c66b2149f50ac97d5c7bfe9e524e4e9f9aa256b95f7ff5ed034d9f9a1ac683510f4b3adc41bd3de3d57233200
|
data/lib/dirfy/cli.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
require "optparse"
|
|
3
|
+
require_relative "version"
|
|
3
4
|
require_relative "parser"
|
|
4
5
|
require_relative "io"
|
|
5
6
|
|
|
@@ -33,6 +34,11 @@ module Dirfy
|
|
|
33
34
|
options[:prefix] = dir.chomp("/") + "/"
|
|
34
35
|
end
|
|
35
36
|
|
|
37
|
+
opts.on("-V", "--version", "Show version") do
|
|
38
|
+
puts "dirfy #{Dirfy::VERSION}"
|
|
39
|
+
exit
|
|
40
|
+
end
|
|
41
|
+
|
|
36
42
|
opts.on("-h", "--help", "Show this help") do
|
|
37
43
|
puts opts
|
|
38
44
|
exit
|
|
@@ -44,8 +50,11 @@ module Dirfy
|
|
|
44
50
|
lines =
|
|
45
51
|
if argv[0] && File.file?(argv[0])
|
|
46
52
|
File.readlines(argv[0]).map(&:chomp)
|
|
47
|
-
|
|
53
|
+
elsif !STDIN.tty?
|
|
48
54
|
STDIN.read.lines.map(&:chomp)
|
|
55
|
+
else
|
|
56
|
+
puts parser.to_s
|
|
57
|
+
exit(0)
|
|
49
58
|
end
|
|
50
59
|
|
|
51
60
|
items = Parser.new(indent: options[:indent]).parse(lines)
|
data/lib/dirfy/parser.rb
CHANGED
|
@@ -13,6 +13,8 @@ module Dirfy
|
|
|
13
13
|
def parse(lines)
|
|
14
14
|
stack = []
|
|
15
15
|
items = []
|
|
16
|
+
depths = []
|
|
17
|
+
names = []
|
|
16
18
|
|
|
17
19
|
lines.each do |raw|
|
|
18
20
|
line = raw.rstrip
|
|
@@ -31,14 +33,24 @@ module Dirfy
|
|
|
31
33
|
|
|
32
34
|
stack[depth] = name
|
|
33
35
|
stack = stack[0..depth]
|
|
34
|
-
|
|
35
|
-
# build full path
|
|
36
|
+
# build full path (no trailing slash yet)
|
|
36
37
|
path = stack.map { |c| c.chomp("/") }.join("/")
|
|
37
|
-
|
|
38
|
+
depths << depth
|
|
39
|
+
names << name
|
|
38
40
|
items << path
|
|
39
41
|
end
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
# Second pass: infer directories by depth
|
|
44
|
+
items.each_with_index.map do |path, i|
|
|
45
|
+
is_dir = directory?(names[i], i, depths)
|
|
46
|
+
is_dir ? (path.end_with?("/") ? path : "#{path}/") : path
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def directory?(name, index, depths)
|
|
53
|
+
name.end_with?("/") || (index < depths.size - 1 && depths[index + 1] > depths[index])
|
|
42
54
|
end
|
|
43
55
|
end
|
|
44
56
|
end
|
data/lib/dirfy/version.rb
CHANGED