dorian-git-tree 0.1.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dorian/git/tree.rb +59 -16
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db9e5c485461690eb5d6c477b7ee19800310a7ed75cc344a75ce4e010a84f39a
|
4
|
+
data.tar.gz: 2754c9fb19a4ea50b1caf7d456fac5407964d94f572e560b68d41bad4eb49a3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bf1564b380bb50e76d70772cc9d58a8bea580a57d7a15de717906a7da535f7a36d1398c4c5aa651a70f014ed37d8fc75a0542215e87dc6d81d9326025091604
|
7
|
+
data.tar.gz: d4fdd7e69ed9f1c0802a6c7c83368d6937ae19321560b5ee9616c896a49573e98f28422b07076122803ef0fcc3752f360848e027dce502a30efbd91a727008d4
|
data/lib/dorian/git/tree.rb
CHANGED
@@ -1,30 +1,73 @@
|
|
1
|
-
require
|
1
|
+
require "shellwords"
|
2
2
|
|
3
3
|
module Dorian
|
4
4
|
module Git
|
5
5
|
class Tree
|
6
|
+
SPACE = " "
|
7
|
+
RIGHT = "└── "
|
8
|
+
DOWN = "│ "
|
9
|
+
DOWN_AND_RIGHT = "├── "
|
10
|
+
|
6
11
|
def self.run
|
7
|
-
|
8
|
-
|
12
|
+
if ARGV[0] == "--help" || ARGV[0] == "-h" || ARGV.size > 1
|
13
|
+
puts "USAGE: git tree [PATH]"
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
key = ARGV.first || "."
|
18
|
+
|
19
|
+
files = git_ls_files(key).map do |file|
|
20
|
+
ARGV.first ? file.sub(ARGV.first, "") : file
|
21
|
+
end
|
22
|
+
|
23
|
+
values = group(files)
|
9
24
|
|
10
|
-
|
25
|
+
key = "#{key}/" if values.any? && key != "." && key[-1] != "/"
|
11
26
|
|
12
|
-
|
13
|
-
|
27
|
+
puts key
|
28
|
+
|
29
|
+
values.each.with_index do |(value_key, value_values), value_index|
|
30
|
+
print(
|
31
|
+
key: value_key,
|
32
|
+
values: value_values,
|
33
|
+
index: value_index,
|
34
|
+
size: values.size,
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.git_ls_files(path)
|
40
|
+
result = `#{["git", "ls-files", path].compact.shelljoin}`.split("\n")
|
41
|
+
exit $?.exitstatus if $?.exitstatus > 0
|
42
|
+
result
|
43
|
+
end
|
14
44
|
|
15
|
-
|
16
|
-
|
17
|
-
.
|
18
|
-
|
19
|
-
|
20
|
-
|
45
|
+
def self.group(files)
|
46
|
+
files
|
47
|
+
.group_by { |file| file.split("/").first }
|
48
|
+
.transform_values do |values|
|
49
|
+
group(
|
50
|
+
values
|
51
|
+
.map { |value| value.split("/")[1..-1].join("/") }
|
52
|
+
.reject(&:empty?)
|
53
|
+
)
|
21
54
|
end
|
22
55
|
end
|
23
56
|
|
24
|
-
def self.
|
25
|
-
|
26
|
-
|
27
|
-
|
57
|
+
def self.print(key:, values:, index: 0, size: 1, prefix: "")
|
58
|
+
key = "#{key}/" if values.any?
|
59
|
+
last = index + 1 == size
|
60
|
+
right_prefix = last ? RIGHT : DOWN_AND_RIGHT
|
61
|
+
puts prefix + right_prefix + key
|
62
|
+
values.each.with_index do |(value_key, value_values), value_index|
|
63
|
+
print(
|
64
|
+
key: value_key,
|
65
|
+
values: value_values,
|
66
|
+
index: value_index,
|
67
|
+
size: values.size,
|
68
|
+
prefix: prefix + (last ? SPACE : DOWN)
|
69
|
+
)
|
70
|
+
end
|
28
71
|
end
|
29
72
|
end
|
30
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dorian-git-tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Lists your files and directories in your git repository as a tree
|
@@ -25,7 +25,8 @@ files:
|
|
25
25
|
homepage: https://github.com/dorianmariefr/git-tree
|
26
26
|
licenses:
|
27
27
|
- MIT
|
28
|
-
metadata:
|
28
|
+
metadata:
|
29
|
+
rubygems_mfa_required: 'true'
|
29
30
|
post_install_message:
|
30
31
|
rdoc_options: []
|
31
32
|
require_paths:
|