dorian-git-tree 0.1.0 → 0.2.1

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 +51 -15
  3. metadata +9 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cbb35e06fdb53882fda7e48dbf46c9b0576ca4e75aaba5e99a7485754ea72a6
4
- data.tar.gz: 91f949eee7bfb3939c610d79936c017660cd20dfa75b716646837b6499472564
3
+ metadata.gz: 762b4e2cd1593f83a9a6dda5fb0442a4d4ecd8860c6f6adc25720740d33b07a7
4
+ data.tar.gz: d1f0a23425cee2ffa20a0815b75dd01c424bd45db9bf83921757a2c6ca0a7db0
5
5
  SHA512:
6
- metadata.gz: c1d6839c7b46ddca156ac56aa5106a0dc7712d1fe6951b6cc1e43ad8e6dca660f82daf3e2f9b4387cd874d0412617cc9ebbd338ebd5b43dd232088fc6bfb3e90
7
- data.tar.gz: 2a82615674b7fb29d25475e89f7ce797a254dab3d1b0c0d51c662e59931de6c7dd2ab67544540074ae584ce5b086a177511b6ed43660d70e62cda538d63dd706
6
+ metadata.gz: 9211aa65935897be97707376c9b75a0f45d12472a142a9e0c7ba91827e69e20cf3178989e3c79995e720b7a35999af0e589ff29e17c34f55f67e04cc1fedde5f
7
+ data.tar.gz: 1d7266f1f0f06a985090baa605b4c5c44148345bcc8cd7f3fd5ddaa6d7160e8332d96ed9b8b5f857bbc18b5fa26b4ac4d723db69b8fd1f8391588e801f80d33f
@@ -1,28 +1,64 @@
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
9
16
 
10
- private
17
+ key = ARGV.first || "."
18
+ files = git_ls_files(key)
19
+ values = group(files)
20
+ key = "#{key}/" if values.any? && key != "." && key[-1] != "/"
21
+ puts key
22
+ values.each.with_index do |(value_key, value_values), value_index|
23
+ print(
24
+ key: value_key,
25
+ values: value_values,
26
+ index: value_index,
27
+ size: values.size,
28
+ )
29
+ end
30
+ end
11
31
 
12
- def self.list(dir, start: true)
13
- puts dir if start
32
+ def self.git_ls_files(path)
33
+ `#{["git", "ls-files", path].compact.shelljoin}`.split("\n")
34
+ end
14
35
 
15
- `git ls-tree HEAD #{Shellwords.escape(dir)} --name-only`.split("\n").sort.each do |line|
16
- split = line.split('/')
17
- puts format(line)
18
- list(line + '/', start: false) if File.directory?(line)
19
- end
36
+ def self.group(files)
37
+ files
38
+ .group_by { |file| file.split("/").first }
39
+ .transform_values do |values|
40
+ group(
41
+ values
42
+ .map { |value| value.split("/")[1..-1].join("/") }
43
+ .reject(&:empty?)
44
+ )
45
+ end
20
46
  end
21
47
 
22
- def self.format(file)
23
- split = file.split('/')
24
- return file unless split.size > 1
25
- "│ " * (split.size - 2) + "└── " + split.last
48
+ def self.print(key:, values:, index: 0, size: 1, prefix: "")
49
+ key = "#{key}/" if values.any?
50
+ last = index + 1 == size
51
+ right_prefix = last ? RIGHT : DOWN_AND_RIGHT
52
+ puts prefix + right_prefix + key
53
+ values.each.with_index do |(value_key, value_values), value_index|
54
+ print(
55
+ key: value_key,
56
+ values: value_values,
57
+ index: value_index,
58
+ size: values.size,
59
+ prefix: prefix + (last ? SPACE : DOWN)
60
+ )
61
+ end
26
62
  end
27
63
  end
28
64
  end
metadata CHANGED
@@ -1,16 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-git-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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: 2021-10-08 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: e.g. `git-tree config/`
13
+ description: |-
14
+ Lists your files and directories in your git repository as a tree
15
+
16
+ e.g. `git-tree config/`
14
17
  email: dorian@dorianmarie.fr
15
18
  executables:
16
19
  - git-tree
@@ -22,7 +25,8 @@ files:
22
25
  homepage: https://github.com/dorianmariefr/git-tree
23
26
  licenses:
24
27
  - MIT
25
- metadata: {}
28
+ metadata:
29
+ rubygems_mfa_required: 'true'
26
30
  post_install_message:
27
31
  rdoc_options: []
28
32
  require_paths:
@@ -38,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
42
  - !ruby/object:Gem::Version
39
43
  version: '0'
40
44
  requirements: []
41
- rubygems_version: 3.2.19
45
+ rubygems_version: 3.2.22
42
46
  signing_key:
43
47
  specification_version: 4
44
48
  summary: Lists your files and directories in your git repository as a tree