dorian-git-tree 0.1.2 → 0.2.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 +50 -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: 04af5c2eb017066ef0c51c4e4a9be09fe0db93fe1910c21dd5d548193f2435c0
4
+ data.tar.gz: b5cb32c3cec0101276085e2b10497a5d8a0dacab5ec034229c470cc8afa7e5fd
5
5
  SHA512:
6
- metadata.gz: f308c7395bbac715d1697e32358be0a0260555f0fe30839bd12f96d6dbbc22690da1d0f6222643803e940835cfafd8eb8db74c0339773b1038b12900dccbe6c5
7
- data.tar.gz: 8db11420cb797c0d458ffaaf4f75e7a00ce907251bcbddf8934c96487b49af23c3e452e16e1bb15ec8c2f9ef4c55877abc787f83185c239e1299b4c7a20225f0
6
+ metadata.gz: 156fb05f12b601339ee98bcfa4ad6a208b607748b1743f4b5e123056d428eeb361a18e8b8182b5e0973b409a105319f3e5a0d1c11ceaba51d5e3c860290bdb08
7
+ data.tar.gz: 0c2f4230381f94549ec95145735f1816da1db669ef206371be10b6944c2f3076dbdac0c8db0219220ca7fe93ccfe949f7233daf2d7915f46e98714497cdacb30
@@ -1,30 +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 != "."
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")
16
- .sort
17
- .each do |line|
18
- split = line.split('/')
19
- puts format(line)
20
- list(line + '/', start: false) if File.directory?(line)
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
+ )
21
45
  end
22
46
  end
23
47
 
24
- def self.format(file)
25
- split = file.split('/')
26
- return file unless split.size > 1
27
- '│ ' * (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
28
62
  end
29
63
  end
30
64
  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.2.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-19 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: