notes-cli 1.0.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.
- data/bin/notes +23 -0
- data/lib/notes-cli.rb +103 -0
- data/lib/notes-cli/version.rb +3 -0
- metadata +49 -0
data/bin/notes
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'notes-cli'
|
4
|
+
|
5
|
+
if ARGV.any? { |arg| ["-h", "--help"].include?(arg) }
|
6
|
+
puts %Q{\
|
7
|
+
Usage: notes [DIRECTORY=.] [-f FILES] [-e EXCLUDES]
|
8
|
+
|
9
|
+
Options:
|
10
|
+
-f, --flags # List of custom annotations, ex: '-f broken refactor' (case insensitive)
|
11
|
+
-e, --exclude # List of directories to ignore, ex: '-e tmp/ log/'
|
12
|
+
-h, --help # Display this menu
|
13
|
+
|
14
|
+
Examples:
|
15
|
+
notes # Show default annotations for all files in current directory (default)
|
16
|
+
notes app/ -f broken # Only examine files in the app/ directory and add the 'broken' flag
|
17
|
+
|
18
|
+
}
|
19
|
+
exit(0)
|
20
|
+
end
|
21
|
+
|
22
|
+
Notes.build_options(ARGV)
|
23
|
+
Notes.find_all
|
data/lib/notes-cli.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
class Notes
|
2
|
+
attr_accessor :options
|
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
|
+
# Read and parse all files as specified in the options
|
70
|
+
def find_all
|
71
|
+
Notes.files.each do |filename|
|
72
|
+
name = filename.gsub(Dir.pwd, '')
|
73
|
+
File.open(filename, "r") { |file| Notes.parse_file(name, file) }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Scan a file for annotations and output numbered lines for each
|
78
|
+
def parse_file(name, file)
|
79
|
+
counter = 1
|
80
|
+
tasks = []
|
81
|
+
|
82
|
+
file.each_line do |line|
|
83
|
+
if @options[:flags].any? { |flag| line.include?(flag) || line.include?(flag.downcase) }
|
84
|
+
tasks << {
|
85
|
+
:line_num => counter,
|
86
|
+
:line => line.strip
|
87
|
+
}
|
88
|
+
end
|
89
|
+
counter += 1
|
90
|
+
end
|
91
|
+
|
92
|
+
if !tasks.empty?
|
93
|
+
name.slice!(0) if name.start_with?("/")
|
94
|
+
puts "#{name}:"
|
95
|
+
tasks.each { |task| puts " ln #{task[:line_num]}: #{task[:line]}" }
|
96
|
+
puts ""
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: notes-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Berls
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-13 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email: andrew.berls@gmail.com
|
16
|
+
executables:
|
17
|
+
- notes
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/notes-cli.rb
|
22
|
+
- lib/notes-cli/version.rb
|
23
|
+
- bin/notes
|
24
|
+
homepage: https://github.com/andrewberls/notes-cli
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.24
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: A tool for managing source code annotations
|
48
|
+
test_files: []
|
49
|
+
has_rdoc:
|