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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dorian/git/tree.rb +59 -16
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb002166fb2e78caa5668ba160022eb5765d2d372ab811fff3041164d8726d7e
4
- data.tar.gz: 1ee4d98c0b4c7aae9ea5bc26caa60deb0f53bd5ed48f032a6053eec2691c1bbe
3
+ metadata.gz: db9e5c485461690eb5d6c477b7ee19800310a7ed75cc344a75ce4e010a84f39a
4
+ data.tar.gz: 2754c9fb19a4ea50b1caf7d456fac5407964d94f572e560b68d41bad4eb49a3c
5
5
  SHA512:
6
- metadata.gz: f308c7395bbac715d1697e32358be0a0260555f0fe30839bd12f96d6dbbc22690da1d0f6222643803e940835cfafd8eb8db74c0339773b1038b12900dccbe6c5
7
- data.tar.gz: 8db11420cb797c0d458ffaaf4f75e7a00ce907251bcbddf8934c96487b49af23c3e452e16e1bb15ec8c2f9ef4c55877abc787f83185c239e1299b4c7a20225f0
6
+ metadata.gz: 5bf1564b380bb50e76d70772cc9d58a8bea580a57d7a15de717906a7da535f7a36d1398c4c5aa651a70f014ed37d8fc75a0542215e87dc6d81d9326025091604
7
+ data.tar.gz: d4fdd7e69ed9f1c0802a6c7c83368d6937ae19321560b5ee9616c896a49573e98f28422b07076122803ef0fcc3752f360848e027dce502a30efbd91a727008d4
@@ -1,30 +1,73 @@
1
- require 'shellwords'
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
- list(ARGV.first || '.')
8
- end
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
- private
25
+ key = "#{key}/" if values.any? && key != "." && key[-1] != "/"
11
26
 
12
- def self.list(dir, start: true)
13
- puts dir if start
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
- `git ls-tree HEAD #{Shellwords.escape(dir)} --name-only`.split("\n")
16
- .sort
17
- .each do |line|
18
- split = line.split('/')
19
- puts format(line)
20
- list(line + '/', start: false) if File.directory?(line)
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.format(file)
25
- split = file.split('/')
26
- return file unless split.size > 1
27
- '│ ' * (split.size - 2) + '└── ' + split.last
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.1.2
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-10-10 00:00:00.000000000 Z
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: