dorian-git-tree 0.3.2 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/git-tree +61 -2
  3. metadata +18 -5
  4. data/lib/dorian/git/tree.rb +0 -79
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4424818fad63e82abf652b7edcac3b59f695cf2a7b24dd0889a20a8e8f8064a
4
- data.tar.gz: 0545b7c1e65dcca7df4272cc1110e12cbd1fa041bd9088b598c1284c33109559
3
+ metadata.gz: '0697b806c414a667c9b3eb87a82097213d7df0ef19ddd272d66d7df7a7749f72'
4
+ data.tar.gz: 8389bc1b158192a675465cc6b159d7dce00e9f2c63c0e8fbfd64a1b27113ae5b
5
5
  SHA512:
6
- metadata.gz: 11f2811b994063ba6154af10e9aafd37e40c980d93ffb3934237f67f7bf0aa42b225e12d43f342979e640933ca404d1ffe7a662b84d057070dba7edb64ef4c29
7
- data.tar.gz: 3f241d674d57ca35d64fcf1447d619f4dad69f7eca2f288eae9c7bbbac946f4ce2f77e731720dfc52b86ee42f7a923b19aa25c15e2a87f21292611c36a019470
6
+ metadata.gz: 51f4990d0994162ab7a80f1f4ff5ee73c4fded180399c6c16d3a619fcc6c7900bed6bcd76a314772d3758b4f43092e516f153e1304b72eb336da1a52189d193f
7
+ data.tar.gz: 026c75068ef745b31e5a7e4799628d5e5268ba8e1fb4f3981cab81e657c60c1c74b695edf0380cf8ceb3358bd7af55600ddf9aafdafe60a8ddcf241db35f1ebb
data/bin/git-tree CHANGED
@@ -1,5 +1,64 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "dorian/git/tree"
5
- Dorian::Git::Tree.run
4
+ require "git"
5
+
6
+ SPACE = " "
7
+ RIGHT = "└── "
8
+ DOWN = "│   "
9
+ DOWN_AND_RIGHT = "├── "
10
+
11
+ def git_ls_files(path)
12
+ Git.open(".").ls_files(path).map(&:first)
13
+ end
14
+
15
+ def group(files)
16
+ files
17
+ .group_by { |file| file.split("/").first }
18
+ .transform_values do |values|
19
+ group(
20
+ values.map { |value| value.split("/")[1..].join("/") }.reject(&:empty?)
21
+ )
22
+ end
23
+ end
24
+
25
+ def print(key:, values:, index: 0, size: 1, prefix: "")
26
+ key = "#{key}/" if values.any?
27
+ last = index + 1 == size
28
+ right_prefix = last ? RIGHT : DOWN_AND_RIGHT
29
+ puts prefix + right_prefix + key
30
+ values.each.with_index do |(value_key, value_values), value_index|
31
+ print(
32
+ key: value_key,
33
+ values: value_values,
34
+ index: value_index,
35
+ size: values.size,
36
+ prefix: prefix + (last ? SPACE : DOWN)
37
+ )
38
+ end
39
+ end
40
+
41
+ if ARGV[0] == "--help" || ARGV[0] == "-h" || ARGV.size > 1
42
+ puts "USAGE: git tree [PATH]"
43
+ exit
44
+ end
45
+
46
+ key = ARGV.first || "."
47
+
48
+ files =
49
+ git_ls_files(key).map { |file| ARGV.first ? file.sub(ARGV.first, "") : file }
50
+
51
+ values = group(files)
52
+
53
+ key = "#{key}/" if values.any? && key != "." && key[-1] != "/"
54
+
55
+ puts key
56
+
57
+ values.each.with_index do |(value_key, value_values), value_index|
58
+ print(
59
+ key: value_key,
60
+ values: value_values,
61
+ index: value_index,
62
+ size: values.size
63
+ )
64
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-git-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-09 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: git
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
13
27
  description: |-
14
28
  Lists your files and directories in your git repository as a tree
15
29
 
@@ -21,8 +35,7 @@ extensions: []
21
35
  extra_rdoc_files: []
22
36
  files:
23
37
  - bin/git-tree
24
- - lib/dorian/git/tree.rb
25
- homepage: https://github.com/dorianmariecom/git-tree
38
+ homepage: https://github.com/dorianmariecom/dorian-git-tree
26
39
  licenses:
27
40
  - MIT
28
41
  metadata:
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "English"
4
-
5
- require "shellwords"
6
-
7
- module Dorian
8
- module Git
9
- class Tree
10
- SPACE = " "
11
- RIGHT = "└── "
12
- DOWN = "│   "
13
- DOWN_AND_RIGHT = "├── "
14
-
15
- def self.run
16
- if ARGV[0] == "--help" || ARGV[0] == "-h" || ARGV.size > 1
17
- puts "USAGE: git tree [PATH]"
18
- exit
19
- end
20
-
21
- key = ARGV.first || "."
22
-
23
- files =
24
- git_ls_files(key).map do |file|
25
- ARGV.first ? file.sub(ARGV.first, "") : file
26
- end
27
-
28
- values = group(files)
29
-
30
- key = "#{key}/" if values.any? && key != "." && key[-1] != "/"
31
-
32
- puts key
33
-
34
- values.each.with_index do |(value_key, value_values), value_index|
35
- print(
36
- key: value_key,
37
- values: value_values,
38
- index: value_index,
39
- size: values.size
40
- )
41
- end
42
- end
43
-
44
- def self.git_ls_files(path)
45
- result = `#{["git", "ls-files", path].compact.shelljoin}`.split("\n")
46
- exit $CHILD_STATUS.exitstatus if $CHILD_STATUS.exitstatus.positive?
47
- result
48
- end
49
-
50
- def self.group(files)
51
- files
52
- .group_by { |file| file.split("/").first }
53
- .transform_values do |values|
54
- group(
55
- values
56
- .map { |value| value.split("/")[1..].join("/") }
57
- .reject(&:empty?)
58
- )
59
- end
60
- end
61
-
62
- def self.print(key:, values:, index: 0, size: 1, prefix: "")
63
- key = "#{key}/" if values.any?
64
- last = index + 1 == size
65
- right_prefix = last ? RIGHT : DOWN_AND_RIGHT
66
- puts prefix + right_prefix + key
67
- values.each.with_index do |(value_key, value_values), value_index|
68
- print(
69
- key: value_key,
70
- values: value_values,
71
- index: value_index,
72
- size: values.size,
73
- prefix: prefix + (last ? SPACE : DOWN)
74
- )
75
- end
76
- end
77
- end
78
- end
79
- end