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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9baf3d0385df461b2d8557113658e3a9c49a6410e96bf81022fe72956c0b958f
4
- data.tar.gz: 2358d42079537d3f2c8d9de9ca0518381add42673b0838c690d4ad57d09792da
3
+ metadata.gz: e8e6bf9d28ac3108a8de6bc541c8c0e2b63fdd101bcf973bcbad6369d87b6dc5
4
+ data.tar.gz: 0e925d19a257eeb53d9ab97f826056cd0c063bd7ec44ef44242aea30dec3b24f
5
5
  SHA512:
6
- metadata.gz: d1a052b6c69e6d8bc7fc7a99564a15f6336f949c942649c5c0bb904fe7070c3b1b719b2a8e9d965c096d33d444925876bcdbe7beab3a59c945fedafb5f756649
7
- data.tar.gz: db1c3f4085caa42ac0360d23b4228d16d576f3e371e85eba27c4f3612cb407ec76dcfb97381917c5bf007e9bc0b65d2023dab072573b4d0547baec21afa880ae
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
- else
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
- path << "/" if name.end_with?("/")
38
+ depths << depth
39
+ names << name
38
40
  items << path
39
41
  end
40
42
 
41
- items
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Dirfy
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dirfy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name