notes-cli 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/bin/notes +4 -3
- data/lib/notes-cli.rb +2 -114
- data/lib/notes-cli/cli.rb +65 -0
- data/lib/notes-cli/opts.rb +61 -0
- data/lib/notes-cli/version.rb +2 -2
- metadata +22 -8
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDVlYWYwYTAwMGM0ZDVmMTlkMTYzOTFkZGM4NDk2NDRkYTgxMzIwMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTY5ZGIxZjFhNDYxMzYxNmJlYTZjMWI2YWYxNDFkNjZkOTc3OGY1Yw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MGQ4NTExODhiZmYwYTk1NjI5N2JmMzRmYTFjMGI1YzdmOWVhZTQwYTg1NDMz
|
10
|
+
ZjgyMTI4ZTgxN2U5MTY4NzNkOWMyODMwODkwYTM2NDkyYjcyZjYzZGU2YjUx
|
11
|
+
MTgxZTEzZjk4YzI0MTUzY2Y1NzcxOGQyMDgxMTBlMTgyYTUyYzY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTIwZjcwOGZjYTQyZTlhYjBkNGVlNmZlOTcwZDZhZDU3NmJhZjlhNmY5Y2Ri
|
14
|
+
MzQ5YzE0Y2U4ZmQ0YjU2YWEwYzQ1ZWUxYTUzNDU5NTQzOWY5YjYwNDA2ZWZm
|
15
|
+
ZjI2MzVkYzNlMWQ5MzQ5YWVkMGMzNWFjMDc5MjdjN2M2NWExZTk=
|
data/bin/notes
CHANGED
@@ -6,7 +6,7 @@ if ARGV.any? { |arg| ["-h", "--help"].include?(arg) }
|
|
6
6
|
puts %Q{\
|
7
7
|
Recursively search source files for annotations. Default annotations are TODO, OPTIMIZE, and FIXME.
|
8
8
|
|
9
|
-
Usage: notes [DIRECTORY=.] [-f
|
9
|
+
Usage: notes [DIRECTORY=. | FILENAMES] [-f FLAGS] [-e EXCLUDES]
|
10
10
|
|
11
11
|
Options:
|
12
12
|
-f, --flags # List of custom annotations, ex: '-f broken refactor' (case insensitive)
|
@@ -16,10 +16,11 @@ Options:
|
|
16
16
|
Examples:
|
17
17
|
notes # Show default annotations for all files in current directory (default)
|
18
18
|
notes app/ -f broken # Only examine files in the app/ directory and add the 'broken' flag
|
19
|
+
notes app/ -e logs/ # Show default annotations for files in app/ directory, excluding files in logs/
|
20
|
+
notes one.rb two.rb # Show default annotations for one.rb and two.rb
|
19
21
|
|
20
22
|
}
|
21
23
|
exit(0)
|
22
24
|
end
|
23
25
|
|
24
|
-
Notes.
|
25
|
-
Notes.find_all
|
26
|
+
Notes::CLI.new.find_all
|
data/lib/notes-cli.rb
CHANGED
@@ -1,114 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
class << self
|
5
|
-
|
6
|
-
# Parse ARGV into a directory and list of argument groups
|
7
|
-
# For example, given ['app/', -f', 'refactor', 'broken', '--exclude', 'tmp', 'log']:
|
8
|
-
# => [ 'app/', ['-f', 'refactor', 'broken'], ['--exclude', 'tmp', 'log'] ]
|
9
|
-
def parse_argv(args)
|
10
|
-
result = []
|
11
|
-
buf = []
|
12
|
-
dir = args.first
|
13
|
-
|
14
|
-
if args.empty? || dir.start_with?("-")
|
15
|
-
# No dir was passed, use current dir
|
16
|
-
result << Dir.pwd
|
17
|
-
else
|
18
|
-
# Dir was passed in
|
19
|
-
dir = Dir.pwd if dir == '.'
|
20
|
-
result << dir
|
21
|
-
args = args.drop(1)
|
22
|
-
end
|
23
|
-
|
24
|
-
args.each do |arg|
|
25
|
-
if arg.start_with?('-')
|
26
|
-
result << buf unless buf.empty?
|
27
|
-
buf = []
|
28
|
-
end
|
29
|
-
buf << arg
|
30
|
-
end
|
31
|
-
|
32
|
-
result << buf
|
33
|
-
end
|
34
|
-
|
35
|
-
# Append any command line arguments to a default set of arguments
|
36
|
-
# arg_list is a directory and argument groups parsed from ARGV. For example:
|
37
|
-
# [ "app/", ['-f', 'refactor', 'broken'], ['--exclude', 'tmp', 'log'] ]
|
38
|
-
def build_options(argv)
|
39
|
-
arg_list = Notes.parse_argv(argv)
|
40
|
-
options = {
|
41
|
-
:flags => %w(TODO FIXME OPTIMIZE),
|
42
|
-
:exclude => []
|
43
|
-
}
|
44
|
-
|
45
|
-
options[:dir] = arg_list.shift
|
46
|
-
|
47
|
-
arg_list.reject(&:empty?).each do |set|
|
48
|
-
flag, *args = set
|
49
|
-
args.map! { |arg| arg.delete("/") } # "log/" => "log"
|
50
|
-
|
51
|
-
case flag
|
52
|
-
when '-f', '--flags' then options[:flags].concat(args)
|
53
|
-
when '-e', '--exclude' then options[:exclude].concat(args)
|
54
|
-
else puts "Unknown argument: #{flag}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
@options = options
|
59
|
-
end
|
60
|
-
|
61
|
-
# List of files to scan for notes as specified in the options
|
62
|
-
def files
|
63
|
-
pattern = File.join(@options[:dir], "**/*")
|
64
|
-
Dir[pattern].reject do |f|
|
65
|
-
File.directory?(f) || @options[:exclude].any? { |dir| File.dirname(f).include?(dir) }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# Scan a file for annotations and output numbered lines for each
|
70
|
-
def parse_file(filename)
|
71
|
-
name = filename.gsub(Dir.pwd, '')
|
72
|
-
counter = 1
|
73
|
-
tasks = []
|
74
|
-
|
75
|
-
begin
|
76
|
-
File.read(filename).each_line do |line|
|
77
|
-
if @options[:flags].any? { |flag| line =~ /#{flag}/i }
|
78
|
-
tasks << {
|
79
|
-
:line_num => counter,
|
80
|
-
:line => line.strip
|
81
|
-
}
|
82
|
-
end
|
83
|
-
counter += 1
|
84
|
-
end
|
85
|
-
rescue
|
86
|
-
# Error occurred reading the file (ex. invalid byte sequence in UTF-8)
|
87
|
-
# Move on quietly
|
88
|
-
end
|
89
|
-
|
90
|
-
if !tasks.empty?
|
91
|
-
name.slice!(0) if name.start_with?("/")
|
92
|
-
puts "#{name}:"
|
93
|
-
|
94
|
-
tasks.each do |task|
|
95
|
-
flag_regex = Regexp.new(@options[:flags].join('|'), true)
|
96
|
-
color = 33 # yellow
|
97
|
-
line = task[:line].gsub(flag_regex) do |flag|
|
98
|
-
"\e[#{color};1m#{flag}\033[0m"
|
99
|
-
end
|
100
|
-
puts " ln #{task[:line_num]}: #{line}"
|
101
|
-
end
|
102
|
-
|
103
|
-
puts ""
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# Read and parse all files as specified in the options
|
108
|
-
def find_all
|
109
|
-
Notes.files.each { |f| Notes.parse_file(f) }
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
1
|
+
require 'notes-cli/opts'
|
2
|
+
require 'notes-cli/cli'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
module Notes
|
3
|
+
class CLI
|
4
|
+
attr_accessor :options
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@options = Opts.parse(ARGV)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Print a formatted task, with highlighting
|
11
|
+
def print_task(task)
|
12
|
+
flag_regex = Regexp.new(@options[:flags].join('|'), true)
|
13
|
+
color = 33 # yellow
|
14
|
+
line = task[:line].gsub(flag_regex) do |flag|
|
15
|
+
"\e[#{color};1m#{flag}\033[0m"
|
16
|
+
end
|
17
|
+
|
18
|
+
puts " ln #{task[:line_num]}: #{line}"
|
19
|
+
end
|
20
|
+
|
21
|
+
# Scan a file for annotations and output numbered lines for each
|
22
|
+
def parse_file(filename)
|
23
|
+
name = filename.gsub(Dir.pwd, '')
|
24
|
+
counter = 1
|
25
|
+
tasks = []
|
26
|
+
|
27
|
+
begin
|
28
|
+
File.read(filename).each_line do |line|
|
29
|
+
if @options[:flags].any? { |flag| line =~ /#{flag}/i }
|
30
|
+
tasks << {
|
31
|
+
:line_num => counter,
|
32
|
+
:line => line.strip
|
33
|
+
}
|
34
|
+
end
|
35
|
+
counter += 1
|
36
|
+
end
|
37
|
+
rescue
|
38
|
+
# Error occurred reading the file (ex. invalid byte sequence in UTF-8)
|
39
|
+
# Move on quietly
|
40
|
+
end
|
41
|
+
|
42
|
+
if !tasks.empty?
|
43
|
+
name.slice!(0) if name.start_with?("/")
|
44
|
+
puts "#{name}:"
|
45
|
+
tasks.each { |t| print_task(t) }
|
46
|
+
puts ""
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Read and parse all files as specified in the options
|
51
|
+
def find_all
|
52
|
+
@options[:locations].each do |loc|
|
53
|
+
if File.directory?(loc)
|
54
|
+
Dir[ File.join(loc, "**/*") ].reject do |f|
|
55
|
+
File.directory?(f) || @options[:exclude].any? { |dir| File.dirname(f).include?(dir) }
|
56
|
+
end.each { |f| parse_file(f) }
|
57
|
+
else
|
58
|
+
parse_file(loc)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Notes
|
2
|
+
module Opts
|
3
|
+
|
4
|
+
DEFAULT_OPTIONS = {
|
5
|
+
:flags => %w(TODO FIXME OPTIMIZE),
|
6
|
+
:exclude => [],
|
7
|
+
:files => [],
|
8
|
+
:directory => '',
|
9
|
+
}
|
10
|
+
|
11
|
+
FLAG_FLAGS = ['-f', '--flags']
|
12
|
+
EXCLUDE_FLAGS = ['-e', '--exclude']
|
13
|
+
ALL_FLAGS = FLAG_FLAGS + EXCLUDE_FLAGS
|
14
|
+
|
15
|
+
# Parse ARGV into a directory and list of argument groups
|
16
|
+
# For example, given ['app/', -f', 'refactor', 'broken', '--exclude', 'tmp', 'log']:
|
17
|
+
# => [ ['app/'], ['-f', 'refactor', 'broken'], ['--exclude', 'tmp', 'log'] ]
|
18
|
+
#
|
19
|
+
def self.arg_groups(args)
|
20
|
+
result = []
|
21
|
+
buf = []
|
22
|
+
|
23
|
+
# No dir was passed, use current dir
|
24
|
+
if args.empty? || args.first.start_with?('-')
|
25
|
+
result << [ Dir.pwd ]
|
26
|
+
end
|
27
|
+
|
28
|
+
args.each do |arg|
|
29
|
+
if ALL_FLAGS.include?(arg)
|
30
|
+
result << buf unless buf.empty?
|
31
|
+
buf = []
|
32
|
+
end
|
33
|
+
buf << arg
|
34
|
+
end
|
35
|
+
|
36
|
+
result << buf
|
37
|
+
end
|
38
|
+
|
39
|
+
# Append any command line arguments to a default set of arguments
|
40
|
+
def self.parse(args)
|
41
|
+
arg_list = arg_groups(args)
|
42
|
+
options = DEFAULT_OPTIONS
|
43
|
+
|
44
|
+
options[:locations] = arg_list.shift
|
45
|
+
|
46
|
+
arg_list.reject(&:empty?).each do |set|
|
47
|
+
flag, *args = set
|
48
|
+
args.map! { |arg| arg.delete("/") } # "log/" => "log"
|
49
|
+
|
50
|
+
case flag
|
51
|
+
when '-f', '--flags' then options[:flags].concat(args)
|
52
|
+
when '-e', '--exclude' then options[:exclude].concat(args)
|
53
|
+
else puts "Unknown argument: #{flag}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
options
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/lib/notes-cli/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "1.0
|
1
|
+
module Notes
|
2
|
+
VERSION = "1.1.0"
|
3
3
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notes-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Andrew Berls
|
@@ -10,7 +9,21 @@ autorequire:
|
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
11
|
date: 2013-01-13 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
14
27
|
description:
|
15
28
|
email: andrew.berls@gmail.com
|
16
29
|
executables:
|
@@ -18,32 +31,33 @@ executables:
|
|
18
31
|
extensions: []
|
19
32
|
extra_rdoc_files: []
|
20
33
|
files:
|
21
|
-
- lib/notes-cli.rb
|
34
|
+
- lib/notes-cli/cli.rb
|
35
|
+
- lib/notes-cli/opts.rb
|
22
36
|
- lib/notes-cli/version.rb
|
37
|
+
- lib/notes-cli.rb
|
23
38
|
- bin/notes
|
24
39
|
homepage: https://github.com/andrewberls/notes-cli
|
25
40
|
licenses: []
|
41
|
+
metadata: {}
|
26
42
|
post_install_message:
|
27
43
|
rdoc_options: []
|
28
44
|
require_paths:
|
29
45
|
- lib
|
30
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
-
none: false
|
32
47
|
requirements:
|
33
48
|
- - ! '>='
|
34
49
|
- !ruby/object:Gem::Version
|
35
50
|
version: '0'
|
36
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
38
52
|
requirements:
|
39
53
|
- - ! '>='
|
40
54
|
- !ruby/object:Gem::Version
|
41
55
|
version: '0'
|
42
56
|
requirements: []
|
43
57
|
rubyforge_project:
|
44
|
-
rubygems_version:
|
58
|
+
rubygems_version: 2.0.3
|
45
59
|
signing_key:
|
46
|
-
specification_version:
|
60
|
+
specification_version: 4
|
47
61
|
summary: A tool for managing source code annotations
|
48
62
|
test_files: []
|
49
63
|
has_rdoc:
|