git_topic 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/git_topic/cli.rb +8 -6
- data/lib/git_topic/commands/add.rb +17 -0
- data/lib/git_topic/commands/list.rb +12 -84
- data/lib/git_topic/formatter/branches.rb +92 -0
- data/lib/git_topic/formatter/helper.rb +18 -0
- data/lib/git_topic/formatter/topics.rb +62 -0
- data/lib/git_topic/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1f5292c4e5a178415318180ff45bf3d5c5b55d0
|
4
|
+
data.tar.gz: fd4e79d7c444a6f054e72da5c4b60ed3d2083a07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 147d88352b5b46ce3a801b81babc5415a52667d61d6fb3874ee612eb2e6d3ab85ae20be764222fe2487259559e2848585231b4d349a3ef6495d3eba7ccea1d6a
|
7
|
+
data.tar.gz: 0a70933433daad90df9a75edc9abb7e75007724f7ab8aeacd147b8148d20fe06873af3e00f5fb3f137219cdcd617ed36f0ac0240635c1e4d5c098fa0f8a2745e
|
data/lib/git_topic/cli.rb
CHANGED
@@ -4,8 +4,9 @@ require 'thor'
|
|
4
4
|
require 'open3'
|
5
5
|
|
6
6
|
require 'git_topic/version'
|
7
|
-
require 'git_topic/commands/
|
7
|
+
require 'git_topic/commands/add'
|
8
8
|
require 'git_topic/commands/edit'
|
9
|
+
require 'git_topic/commands/list'
|
9
10
|
require 'git_topic/commands/show'
|
10
11
|
|
11
12
|
module GitTopic
|
@@ -15,6 +16,7 @@ module GitTopic
|
|
15
16
|
|
16
17
|
desc 'list', 'Show managed topics'
|
17
18
|
option :version, aliases: 'v'
|
19
|
+
option :all, aliases: 'a'
|
18
20
|
def list
|
19
21
|
# Show version if -v specified
|
20
22
|
if options[:version]
|
@@ -22,7 +24,7 @@ module GitTopic
|
|
22
24
|
return
|
23
25
|
end
|
24
26
|
|
25
|
-
command = GitTopic::Commands::List.new
|
27
|
+
command = GitTopic::Commands::List.new options
|
26
28
|
command.execute
|
27
29
|
end
|
28
30
|
|
@@ -43,10 +45,10 @@ module GitTopic
|
|
43
45
|
puts GitTopic::VERSION
|
44
46
|
end
|
45
47
|
|
46
|
-
desc 'add topic_name', 'Remember topic'
|
47
|
-
def add(topic_name)
|
48
|
-
|
49
|
-
|
48
|
+
desc 'add topic_name summary', 'Remember topic'
|
49
|
+
def add(topic_name, summary)
|
50
|
+
command = GitTopic::Commands::Add.new topic_name, summary
|
51
|
+
command.execute
|
50
52
|
end
|
51
53
|
|
52
54
|
desc 'start topic_name', 'Transfer topic_name to branch to implement code'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitTopic
|
4
|
+
module Commands
|
5
|
+
# add command register topic summary
|
6
|
+
class Add
|
7
|
+
def initialize(topic_name, summary)
|
8
|
+
@topic_name = topic_name
|
9
|
+
@summary = summary
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute
|
13
|
+
system("git config --add topic.#{@topic_name} #{@summary}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,96 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'git_topic/formatter/branches'
|
4
|
+
require 'git_topic/formatter/topics'
|
4
5
|
|
5
6
|
module GitTopic
|
6
7
|
module Commands
|
7
8
|
# list command shows summarized topic information
|
8
9
|
class List
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
print_header(branches.first)
|
13
|
-
print_contents(branches, current_branch)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
Branch = Struct.new('Branch', :name, :rev)
|
19
|
-
|
20
|
-
def print_header(branch)
|
21
|
-
rev_length = branch.rev.length
|
22
|
-
header_format = " %-20s %-#{rev_length}s %s"
|
23
|
-
puts format(header_format, :Branch, :Rev, :Summary)
|
24
|
-
puts '-' * 80
|
10
|
+
def initialize(options = {})
|
11
|
+
@options = options
|
12
|
+
@all = options[:all]
|
25
13
|
end
|
26
14
|
|
27
|
-
def
|
28
|
-
branches.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
branches = []
|
35
|
-
current_branch = nil
|
36
|
-
_stdin, stdout, _stderr, _wait_thr = *Open3.popen3('git branch -v')
|
37
|
-
stdout.each do |line|
|
38
|
-
branch_name, rev, current_candidate = parse_branch(line)
|
39
|
-
current_branch ||= current_candidate
|
40
|
-
branches << Branch.new(branch_name, rev)
|
41
|
-
end
|
42
|
-
[branches, current_branch]
|
43
|
-
end
|
44
|
-
|
45
|
-
BRANCH_FORMAT = /
|
46
|
-
\s*(?<current_exp>\*\ )?
|
47
|
-
(?<branch_name>\S+)\s+
|
48
|
-
(?<rev>\S+)\s+(.*)
|
49
|
-
/x
|
50
|
-
|
51
|
-
def parse_branch(line)
|
52
|
-
matched = line.match(BRANCH_FORMAT)
|
53
|
-
raise 'cannot parse branch' unless matched
|
54
|
-
branch_name = matched[:branch_name]
|
55
|
-
rev = matched[:rev]
|
56
|
-
current_branch = matched[:current_exp] ? branch_name : nil
|
57
|
-
[branch_name, rev, current_branch]
|
58
|
-
end
|
59
|
-
|
60
|
-
def print_line(current_branch, branch)
|
61
|
-
branch_name = branch.name
|
62
|
-
rev = branch.rev
|
63
|
-
description = get_description_of branch
|
64
|
-
return if description.nil?
|
65
|
-
branch_format = branch_format(branch_name, current_branch)
|
66
|
-
truncated_name = truncate(branch_name)
|
67
|
-
puts format("#{branch_format} %s %s", truncated_name, rev, description)
|
68
|
-
end
|
69
|
-
|
70
|
-
def get_description_of(branch)
|
71
|
-
config_key = "branch.#{branch.name}.description"
|
72
|
-
command = "git config #{config_key}"
|
73
|
-
_stdin, stdout, _stderr, _wait_thr = *Open3.popen3(command)
|
74
|
-
return nil if stdout.eof?
|
75
|
-
stdout.readline
|
76
|
-
end
|
77
|
-
|
78
|
-
def branch_format(branch_name, current_branch)
|
79
|
-
if branch_name == current_branch
|
80
|
-
"* #{green}#{bold}%-20s#{clear}"
|
81
|
-
else
|
82
|
-
" #{bold}%-20s#{clear}"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def truncate(str, truncate_at: 20)
|
87
|
-
omission = '...'
|
88
|
-
length_with_room_for_omission = truncate_at - omission.length
|
89
|
-
if str.length > truncate_at
|
90
|
-
"#{str[0, length_with_room_for_omission]}#{omission}"
|
91
|
-
else
|
92
|
-
str
|
93
|
-
end
|
15
|
+
def execute
|
16
|
+
branches = ::GitTopic::Formatter::Branches.new @options
|
17
|
+
branches.print
|
18
|
+
return unless @all
|
19
|
+
puts ''
|
20
|
+
topics = ::GitTopic::Formatter::Topics.new
|
21
|
+
topics.print
|
94
22
|
end
|
95
23
|
end
|
96
24
|
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'git_topic/formatter/helper'
|
4
|
+
require 'term/ansicolor'
|
5
|
+
|
6
|
+
module GitTopic
|
7
|
+
module Formatter
|
8
|
+
# summarizes branches information
|
9
|
+
class Branches
|
10
|
+
include Term::ANSIColor
|
11
|
+
include GitTopic::Formatter::Helper
|
12
|
+
|
13
|
+
def initialize(options)
|
14
|
+
@all = options[:all]
|
15
|
+
end
|
16
|
+
Branch = Struct.new('Branch', :name, :rev)
|
17
|
+
|
18
|
+
def print
|
19
|
+
puts "#{bold}[Branches]#{clear}" if @all
|
20
|
+
branches, current_branch = parse_branches
|
21
|
+
print_header(branches.first)
|
22
|
+
print_contents(branches, current_branch)
|
23
|
+
end
|
24
|
+
|
25
|
+
def print_header(branch)
|
26
|
+
rev_length = branch.rev.length
|
27
|
+
header_format = " %-20s %-#{rev_length}s %s"
|
28
|
+
puts format(header_format, :Branch, :Rev, :Summary)
|
29
|
+
puts '-' * 80
|
30
|
+
end
|
31
|
+
|
32
|
+
def print_contents(branches, current_branch)
|
33
|
+
branches.each do |branch|
|
34
|
+
print_line(current_branch, branch)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_branches
|
39
|
+
branches = []
|
40
|
+
current_branch = nil
|
41
|
+
_stdin, stdout, _stderr, _wait_thr = *Open3.popen3('git branch -v')
|
42
|
+
stdout.each do |line|
|
43
|
+
branch_name, rev, current_candidate = parse_branch(line)
|
44
|
+
current_branch ||= current_candidate
|
45
|
+
branches << Branch.new(branch_name, rev)
|
46
|
+
end
|
47
|
+
[branches, current_branch]
|
48
|
+
end
|
49
|
+
|
50
|
+
BRANCH_FORMAT = /
|
51
|
+
\s*(?<current_exp>\*\ )?
|
52
|
+
(?<branch_name>\S+)\s+
|
53
|
+
(?<rev>\S+)\s+(.*)
|
54
|
+
/x
|
55
|
+
|
56
|
+
def parse_branch(line)
|
57
|
+
matched = line.match(BRANCH_FORMAT)
|
58
|
+
raise 'cannot parse branch' unless matched
|
59
|
+
branch_name = matched[:branch_name]
|
60
|
+
rev = matched[:rev]
|
61
|
+
current_branch = matched[:current_exp] ? branch_name : nil
|
62
|
+
[branch_name, rev, current_branch]
|
63
|
+
end
|
64
|
+
|
65
|
+
def print_line(current_branch, branch)
|
66
|
+
branch_name = branch.name
|
67
|
+
rev = branch.rev
|
68
|
+
description = get_description_of branch
|
69
|
+
return if description.nil?
|
70
|
+
branch_format = branch_format(branch_name, current_branch)
|
71
|
+
truncated_name = truncate(branch_name)
|
72
|
+
puts format("#{branch_format} %s %s", truncated_name, rev, description)
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_description_of(branch)
|
76
|
+
config_key = "branch.#{branch.name}.description"
|
77
|
+
command = "git config #{config_key}"
|
78
|
+
_stdin, stdout, _stderr, _wait_thr = *Open3.popen3(command)
|
79
|
+
return nil if stdout.eof?
|
80
|
+
stdout.readline
|
81
|
+
end
|
82
|
+
|
83
|
+
def branch_format(branch_name, current_branch)
|
84
|
+
if branch_name == current_branch
|
85
|
+
"* #{green}#{bold}%-20s#{clear}"
|
86
|
+
else
|
87
|
+
" #{bold}%-20s#{clear}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitTopic
|
4
|
+
module Formatter
|
5
|
+
# Helper class for Formatter classes
|
6
|
+
module Helper
|
7
|
+
def truncate(str, truncate_at: 20)
|
8
|
+
omission = '...'
|
9
|
+
length_with_room_for_omission = truncate_at - omission.length
|
10
|
+
if str.length > truncate_at
|
11
|
+
"#{str[0, length_with_room_for_omission]}#{omission}"
|
12
|
+
else
|
13
|
+
str
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'term/ansicolor'
|
4
|
+
|
5
|
+
module GitTopic
|
6
|
+
module Formatter
|
7
|
+
# summarizes topics information
|
8
|
+
# Topic means theme that not start to implement
|
9
|
+
class Topics
|
10
|
+
include Term::ANSIColor
|
11
|
+
include GitTopic::Formatter::Helper
|
12
|
+
|
13
|
+
def print
|
14
|
+
puts "#{bold}[Topics]#{clear}"
|
15
|
+
topics = parse_topics
|
16
|
+
print_header
|
17
|
+
print_contents topics
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def print_header
|
23
|
+
header_format = ' %-20s %s'
|
24
|
+
puts format(header_format, :Topic, :Summary)
|
25
|
+
puts '-' * 80
|
26
|
+
end
|
27
|
+
|
28
|
+
Topic = Struct.new('Topic', :name, :summary)
|
29
|
+
LIST_TOPIC_COMMAND = 'git config --get-regexp ^topic.\*'
|
30
|
+
|
31
|
+
def parse_topics
|
32
|
+
topics = []
|
33
|
+
_stdin, stdout, _stderr, _wait_thr = *Open3.popen3(LIST_TOPIC_COMMAND)
|
34
|
+
stdout.each do |line|
|
35
|
+
name, summary = parse_topic(line)
|
36
|
+
topics << Topic.new(name, summary)
|
37
|
+
end
|
38
|
+
topics
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_topic(line)
|
42
|
+
matched = line.match(/topic\.(?<topic_name>\S+)\s+(?<summary>.*)/)
|
43
|
+
raise 'cannot parse topic' unless matched
|
44
|
+
topic_name = matched[:topic_name]
|
45
|
+
summary = matched[:summary]
|
46
|
+
[topic_name, summary]
|
47
|
+
end
|
48
|
+
|
49
|
+
def print_contents(topics)
|
50
|
+
topics.each do |topic|
|
51
|
+
print_line topic
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def print_line(topic)
|
56
|
+
truncated_name = truncate(topic.name)
|
57
|
+
summary = topic.summary
|
58
|
+
puts format(" #{bold}%-20s#{clear} %s", truncated_name, summary)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/git_topic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_topic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroki Kondo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -151,9 +151,13 @@ files:
|
|
151
151
|
- git_topic.gemspec
|
152
152
|
- lib/git_topic.rb
|
153
153
|
- lib/git_topic/cli.rb
|
154
|
+
- lib/git_topic/commands/add.rb
|
154
155
|
- lib/git_topic/commands/edit.rb
|
155
156
|
- lib/git_topic/commands/list.rb
|
156
157
|
- lib/git_topic/commands/show.rb
|
158
|
+
- lib/git_topic/formatter/branches.rb
|
159
|
+
- lib/git_topic/formatter/helper.rb
|
160
|
+
- lib/git_topic/formatter/topics.rb
|
157
161
|
- lib/git_topic/version.rb
|
158
162
|
homepage: https://github.com/kompiro/git_topic
|
159
163
|
licenses:
|