task-list 0.6 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/tl +4 -0
- data/lib/task-list/parser.rb +53 -5
- data/lib/task-list/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16e0448f4451b1050ffa6e3a842f9d0f92fd3ef0
|
4
|
+
data.tar.gz: 1306f7bb84ca55b8e31596d696f6c66778efb608
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6231f7fe1cdc292113c649ae3dd06936c0d1e5043900fa59a13b0a6dd1c6b61e7f2c076db503d8f0e5a1cf1ebc883ff3e629d8a50a8be6bad0c3fd38809ec70
|
7
|
+
data.tar.gz: 5a0cce6a1bb9955ccea2ffaff0bc9eaf9ba94cba28f28964a0d39385eccac380cff66059e8822b8b20f5c287beb541fea8117ac595c93679d4d74b97b9037157
|
data/bin/tl
CHANGED
@@ -8,6 +8,10 @@ options = {}
|
|
8
8
|
OptionParser.new do |opts|
|
9
9
|
opts.banner = "Usage: tl [<query>] [<option> ...]"
|
10
10
|
|
11
|
+
opts.on("-g", "--github", "Format for Github (plain option is inferred)") do
|
12
|
+
options[:github] = true
|
13
|
+
end
|
14
|
+
|
11
15
|
opts.on("-p", "--plain", "No colours in the output") do
|
12
16
|
options[:plain] = true
|
13
17
|
end
|
data/lib/task-list/parser.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require "find"
|
2
|
+
require "pathname"
|
2
3
|
|
3
4
|
module TaskList
|
4
5
|
class Parser
|
5
|
-
attr_reader :files, :tasks, :search_path
|
6
|
+
attr_reader :files, :tasks, :search_path, :github
|
6
7
|
|
7
8
|
def initialize(arguments: [], options: {})
|
8
9
|
self.search_path = options[:search_path]
|
10
|
+
@github = options[:github] if options[:github]
|
9
11
|
@plain = options[:plain] if options[:plain]
|
10
12
|
@type = options[:type].upcase if options[:type]
|
11
13
|
@files = fuzzy_find_files queries: arguments
|
@@ -36,13 +38,31 @@ module TaskList
|
|
36
38
|
unless tasks.empty?
|
37
39
|
puts "#{type}:\n#{'-' * (type.length + 1)}\n"
|
38
40
|
|
41
|
+
if self.github? || self.plain?
|
42
|
+
puts
|
43
|
+
end
|
44
|
+
|
39
45
|
tasks.each do |task|
|
40
|
-
|
46
|
+
if self.github?
|
47
|
+
if Pathname.new(self.search_path).absolute?
|
48
|
+
reference = "#{task[:file].sub(/#{Regexp.escape(self.git_repo_root)}\//, "")}#L#{task[:line_number]}"
|
49
|
+
else
|
50
|
+
search_path_components = File.expand_path(self.search_path).split(File::SEPARATOR)
|
51
|
+
search_path_components.pop
|
52
|
+
parent = File.join(*search_path_components)
|
53
|
+
file = task[:file].sub(/#{Regexp.escape(parent)}\//, "")
|
54
|
+
reference = "#{file}#L#{task[:line_number]}"
|
55
|
+
end
|
41
56
|
|
42
|
-
|
43
|
-
puts " line #{task[:line_number]} in #{task[:file]}"
|
57
|
+
puts "- #{task[:task]} — [#{reference}](#{reference})"
|
44
58
|
else
|
45
|
-
puts
|
59
|
+
puts task[:task]
|
60
|
+
|
61
|
+
if self.plain?
|
62
|
+
puts " line #{task[:line_number]} in #{task[:file]}"
|
63
|
+
else
|
64
|
+
puts " \e[30m\e[1mline #{task[:line_number]} in #{task[:file]}\e[0m"
|
65
|
+
end
|
46
66
|
end
|
47
67
|
end
|
48
68
|
|
@@ -51,6 +71,34 @@ module TaskList
|
|
51
71
|
end
|
52
72
|
end
|
53
73
|
|
74
|
+
def git_repo_root
|
75
|
+
full_search_path = File.expand_path(self.search_path)
|
76
|
+
root_path = full_search_path.dup
|
77
|
+
repo_found = false
|
78
|
+
|
79
|
+
begin
|
80
|
+
if File.directory?(File.join(root_path, ".git"))
|
81
|
+
repo_found = true
|
82
|
+
break
|
83
|
+
end
|
84
|
+
|
85
|
+
directories = root_path.split(File::SEPARATOR)
|
86
|
+
directories.pop
|
87
|
+
root_path = File.join(*directories)
|
88
|
+
end until repo_found
|
89
|
+
|
90
|
+
unless repo_found
|
91
|
+
# FIXME: Show an error message instead of raising an exception
|
92
|
+
raise "No git repo found."
|
93
|
+
end
|
94
|
+
|
95
|
+
root_path
|
96
|
+
end
|
97
|
+
|
98
|
+
def github?
|
99
|
+
!!@github
|
100
|
+
end
|
101
|
+
|
54
102
|
def plain?
|
55
103
|
!!@plain
|
56
104
|
end
|
data/lib/task-list/version.rb
CHANGED