git_toolbox 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/get +1 -1
- data/lib/get/commons/command_issuer.rb +60 -0
- data/lib/get/commons/common.rb +70 -0
- data/lib/get/commons/git.rb +31 -14
- data/lib/get/commons/http_client.rb +79 -0
- data/lib/get/subcommand/changelog/changelog.rb +56 -61
- data/lib/get/subcommand/command.rb +58 -6
- data/lib/get/subcommand/commit/commit.rb +58 -61
- data/lib/get/subcommand/commit/prompt.rb +25 -23
- data/lib/get/subcommand/complete/bash_completion.rb +7 -6
- data/lib/get/subcommand/complete/complete.rb +31 -36
- data/lib/get/subcommand/describe/change.rb +25 -27
- data/lib/get/subcommand/describe/describe.rb +113 -115
- data/lib/get/subcommand/describe/docker/docker.rb +55 -58
- data/lib/get/subcommand/describe/metadata.rb +16 -19
- data/lib/get/subcommand/describe/prerelease.rb +12 -13
- data/lib/get/subcommand/init/init.rb +43 -44
- data/lib/get/subcommand/license/license.rb +78 -56
- data/lib/get/subcommand/license/license_retriever.rb +38 -23
- data/lib/get/subcommand/tree/tree.rb +48 -42
- data/lib/get/version.rb +1 -3
- data/lib/get.rb +47 -34
- metadata +16 -14
@@ -17,70 +17,53 @@
|
|
17
17
|
|
18
18
|
# frozen_string_literal: true
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
require 'get/subcommand/command'
|
20
|
+
require_relative '../../commons/common'
|
21
|
+
require_relative '../../commons/git'
|
22
|
+
require_relative '../command'
|
24
23
|
|
25
24
|
# Class length is disabled as most of its length is given by formatting.
|
26
25
|
# rubocop:disable Metrics/ClassLength
|
27
26
|
# Subcommand, it allow to create a new repository and add an initial, empty commit to it.
|
28
27
|
class Tree < Command
|
29
|
-
def self.command
|
30
|
-
@@command ||= new
|
31
|
-
@@command
|
32
|
-
end
|
33
|
-
|
34
|
-
private_class_method :new
|
35
|
-
|
36
28
|
private
|
37
29
|
|
38
|
-
@@command = nil
|
39
|
-
|
40
|
-
@@usage = 'tree -h|(<subcommand> [<subcommand-options])'
|
41
|
-
@@description = 'Print the tree of commits.'
|
42
|
-
@@subcommands = {}
|
43
|
-
# This block is Optimist configuration. It is as long as the number of options of the command.
|
44
|
-
# rubocop:disable Metrics/BlockLength
|
45
|
-
@@option_parser = Optimist::Parser.new do
|
46
|
-
subcommand_max_length = @@subcommands.keys.map { |k| k.to_s.length }.max
|
47
|
-
subcommand_section = <<~SUBCOMMANDS unless @@subcommands.empty?
|
48
|
-
Subcommands:
|
49
|
-
#{@@subcommands.keys.map { |k| " #{k.to_s.ljust(subcommand_max_length)} => #{@@subcommands[k].description}" }.join("\n")}
|
50
|
-
SUBCOMMANDS
|
51
|
-
usage @@usage
|
52
|
-
synopsis @@description + (subcommand_section.nil? ? '' : "\n") + subcommand_section.to_s
|
53
|
-
educate_on_error
|
54
|
-
stop_on @@subcommands.keys.map(&:to_s)
|
55
|
-
end
|
56
|
-
# rubocop:enable Metrics/BlockLength
|
57
|
-
|
58
30
|
def initialize
|
59
|
-
super(
|
60
|
-
@
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
view_tree
|
31
|
+
super() do
|
32
|
+
@usage = 'tree -h|(<subcommand> [<subcommand-options])'
|
33
|
+
@description = 'Print the tree of commits. ' \
|
34
|
+
'If the output is redirected to a pager (i.e. \'less\'), ' \
|
35
|
+
'you may need to enable the parsing of escape sequences.'
|
36
|
+
@subcommands = {}
|
66
37
|
end
|
67
38
|
end
|
68
39
|
|
69
40
|
def view_tree
|
70
|
-
|
41
|
+
puts transform_log(log)
|
71
42
|
end
|
72
43
|
|
73
44
|
TREE_FORMAT = '%C(bold blue)%h%C(reset)§%C(dim normal)(%cr)%C(reset)§%C(auto)%d%C(reset)§§%n' \
|
74
45
|
'§§§ %C(normal)%an%C(reset)%C(dim normal): %s%C(reset)'
|
75
46
|
|
76
47
|
def log
|
77
|
-
|
48
|
+
CommandIssuer.run(
|
49
|
+
'git',
|
50
|
+
'log',
|
51
|
+
'--all',
|
52
|
+
'--graph',
|
53
|
+
'--decorate=short',
|
54
|
+
'--date-order',
|
55
|
+
'--color',
|
56
|
+
"--pretty=format:\"#{TREE_FORMAT}\""
|
57
|
+
).output
|
78
58
|
end
|
79
59
|
|
80
60
|
TIME_REGEX = /(\([a-z0-9 ,]+\))/
|
81
61
|
TIME_MINIMUM_PADDING = 2
|
82
62
|
|
63
|
+
# rubocop:disable Metrics/MethodLength
|
83
64
|
def transform_log(text)
|
65
|
+
return 'This repository has no commit.' if text.empty?
|
66
|
+
|
84
67
|
split_lines = text.split("\n").map { |element| element.split('§') }
|
85
68
|
# The first line is always a commit line, so it always have a time reference
|
86
69
|
first_line_time = split_lines.first[1]
|
@@ -110,9 +93,32 @@ class Tree < Command
|
|
110
93
|
end
|
111
94
|
.join("\n")
|
112
95
|
end
|
96
|
+
# rubocop:enable Metrics/MethodLength
|
97
|
+
|
98
|
+
protected
|
99
|
+
|
100
|
+
def setup_option_parser
|
101
|
+
@option_parser = Optimist::Parser.new(
|
102
|
+
@usage,
|
103
|
+
full_description,
|
104
|
+
stop_condition
|
105
|
+
) do |usage_header, description, stop_condition|
|
106
|
+
usage usage_header
|
107
|
+
synopsis description
|
108
|
+
educate_on_error
|
109
|
+
stop_on stop_condition
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def setup_action
|
114
|
+
@action = lambda do
|
115
|
+
@options = Common.with_subcommand_exception_handling @option_parser do
|
116
|
+
@option_parser.parse
|
117
|
+
end
|
118
|
+
Common.error 'tree need to be run inside a git repository' unless Git.in_repo?
|
113
119
|
|
114
|
-
|
115
|
-
|
120
|
+
view_tree
|
121
|
+
end
|
116
122
|
end
|
117
123
|
end
|
118
124
|
# rubocop:enable Metrics/ClassLength
|
data/lib/get/version.rb
CHANGED
data/lib/get.rb
CHANGED
@@ -28,48 +28,61 @@ require 'get/subcommand/changelog/changelog'
|
|
28
28
|
require 'get/subcommand/tree/tree'
|
29
29
|
require 'get/version'
|
30
30
|
require 'get/commons/common'
|
31
|
+
require 'get/subcommand/command'
|
31
32
|
|
32
|
-
#
|
33
|
-
|
33
|
+
# Main command of Get.
|
34
|
+
class Get < Command
|
34
35
|
class Error < StandardError; end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
#{@@subcommands.keys.map { |k| " #{k.to_s.ljust(subcommand_max_length)} => #{@@subcommands[k].description}" }.join("\n")}
|
51
|
-
SUBCOMMANDS
|
52
|
-
version "Get version: #{Get::VERSION}"
|
53
|
-
educate_on_error
|
54
|
-
stop_on @@subcommands.keys.map(&:to_s)
|
37
|
+
def initialize
|
38
|
+
super() do
|
39
|
+
@usage = '-h|-v|(<subcommand> [<subcommand-options])'
|
40
|
+
@description = ''
|
41
|
+
@subcommands = {
|
42
|
+
describe: Describe.instance,
|
43
|
+
commit: Commit.instance,
|
44
|
+
init: Init.instance,
|
45
|
+
license: License.instance,
|
46
|
+
complete: Complete.instance,
|
47
|
+
changelog: Changelog.instance,
|
48
|
+
tree: Tree.instance,
|
49
|
+
}
|
50
|
+
end
|
55
51
|
end
|
56
52
|
|
57
|
-
def
|
58
|
-
@
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
53
|
+
def main
|
54
|
+
@action.call
|
55
|
+
end
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def setup_option_parser
|
60
|
+
@option_parser = Optimist::Parser.new(
|
61
|
+
@usage,
|
62
|
+
full_description,
|
63
|
+
GET_VERSION,
|
64
|
+
stop_condition
|
65
|
+
) do |usage_header, description, version, stop_condition|
|
66
|
+
usage usage_header
|
67
|
+
synopsis description
|
68
|
+
version "Get version: #{version}"
|
69
|
+
educate_on_error
|
70
|
+
stop_on stop_condition
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
70
|
-
def
|
71
|
-
|
72
|
-
|
74
|
+
def setup_action
|
75
|
+
@action = lambda do
|
76
|
+
@options = Optimist.with_standard_exception_handling(@option_parser) do
|
77
|
+
@option_parser.parse
|
78
|
+
end
|
79
|
+
educated_error 'No command or option specified' if ARGV.empty?
|
80
|
+
command = ARGV.shift.to_sym
|
81
|
+
if @subcommands.include?(command)
|
82
|
+
@subcommands[command].action.call
|
83
|
+
else
|
84
|
+
educated_error "Unknown subcommand '#{command}'"
|
85
|
+
end
|
73
86
|
end
|
74
87
|
end
|
75
88
|
end
|
metadata
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Speranza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: highline
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 3.0.1
|
19
|
+
version: 2.0.3
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 3.0.1
|
26
|
+
version: 2.0.3
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
28
|
+
name: optimist
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
33
|
+
version: '3.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 3.0.1
|
40
37
|
type: :runtime
|
41
38
|
prerelease: false
|
42
39
|
version_requirements: !ruby/object:Gem::Requirement
|
43
40
|
requirements:
|
44
41
|
- - "~>"
|
45
42
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
43
|
+
version: '3.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.0.1
|
47
47
|
description:
|
48
48
|
email:
|
49
49
|
- alex.speranza@studio.unibo.it
|
@@ -55,8 +55,10 @@ files:
|
|
55
55
|
- bin/get
|
56
56
|
- bin/setup
|
57
57
|
- lib/get.rb
|
58
|
+
- lib/get/commons/command_issuer.rb
|
58
59
|
- lib/get/commons/common.rb
|
59
60
|
- lib/get/commons/git.rb
|
61
|
+
- lib/get/commons/http_client.rb
|
60
62
|
- lib/get/subcommand/changelog/changelog.rb
|
61
63
|
- lib/get/subcommand/command.rb
|
62
64
|
- lib/get/subcommand/commit/commit.rb
|