dorian-git-tree 0.3.2 → 0.4.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/git-tree +61 -2
  3. metadata +19 -6
  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: c4bc2379bc6a4479fab44b8445488de106eceda00467633a8b3da63609c3818e
4
+ data.tar.gz: 449dd3fb52f36dcf7b992e69642dcdecf721232e01a42e9e5f2aaeb68840c861
5
5
  SHA512:
6
- metadata.gz: 11f2811b994063ba6154af10e9aafd37e40c980d93ffb3934237f67f7bf0aa42b225e12d43f342979e640933ca404d1ffe7a662b84d057070dba7edb64ef4c29
7
- data.tar.gz: 3f241d674d57ca35d64fcf1447d619f4dad69f7eca2f288eae9c7bbbac946f4ce2f77e731720dfc52b86ee42f7a923b19aa25c15e2a87f21292611c36a019470
6
+ metadata.gz: 33e48042b40e400fcf610ed35520294256fa64b5e0da0379be06b87566e6372038a011c884d757f4fb03616673511e5637cade0e4765a65039b4069e08407e5c
7
+ data.tar.gz: d3dcade7ca4465db565af515b6c67077cac2bdd78891746c4649d58721a112bc3c8130b2a9ccfa4eac5fcaedb1067cc9e5edf144ed6f20a59db9f6fd2c3cb96f
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.2
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:
@@ -35,7 +48,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
35
48
  requirements:
36
49
  - - ">="
37
50
  - !ruby/object:Gem::Version
38
- version: '0'
51
+ version: 3.3.0
39
52
  required_rubygems_version: !ruby/object:Gem::Requirement
40
53
  requirements:
41
54
  - - ">="
@@ -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