tagrity 0.1.7 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -2
- data/README.md +86 -30
- data/lib/tagrity/cli.rb +10 -41
- data/lib/tagrity/commands/logs.rb +23 -0
- data/lib/tagrity/commands/start.rb +31 -11
- data/lib/tagrity/commands/status.rb +17 -2
- data/lib/tagrity/commands/stop.rb +8 -3
- data/lib/tagrity/config_file.rb +86 -62
- data/lib/tagrity/helper.rb +9 -8
- data/lib/tagrity/provider.rb +0 -7
- data/lib/tagrity/tag_generator.rb +24 -11
- data/lib/tagrity/tlogger.rb +30 -0
- data/lib/tagrity/version.rb +1 -1
- data/sample_config.yml +28 -17
- data/tagrity.gemspec +1 -0
- metadata +19 -5
- data/.byebug_history +0 -4
- data/lib/tagrity/file_callbacks.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42e6594cf3699cc2f960b28ecb7d06b3ec2c75b8f39d9eb9d6296b6385bb5a52
|
4
|
+
data.tar.gz: 7bf5d6fd08a760d9f2c99a7e3419dec5580f0bd040a680cb9081ace9922ea25a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9d20591c5e50bd0d1e662511d1f51095bf91c862b2d1ba7bf38e5c6455a80bcbdcaab1b59831af4a6dcaee53fe74b6dfa04e9090b1a7d0cc9a2382c59b2fce2
|
7
|
+
data.tar.gz: c8ac398b851e39503f9a68d8c8655dadadbddaff7d5ff82ff5843ec555ac52ec586d6be39f0456440187742f31fb53343ab1605b14c7f6a4a4426eded189caf6
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tagrity (0.1.
|
4
|
+
tagrity (0.1.11)
|
5
|
+
cli-ui (~> 1.3.0)
|
5
6
|
listen (~> 3.0)
|
6
7
|
pry (~> 0.9.9)
|
7
8
|
thor (~> 0.20)
|
@@ -9,6 +10,7 @@ PATH
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
11
12
|
specs:
|
13
|
+
cli-ui (1.3.0)
|
12
14
|
coderay (1.1.2)
|
13
15
|
diff-lcs (1.3)
|
14
16
|
ffi (1.11.3)
|
@@ -22,7 +24,7 @@ GEM
|
|
22
24
|
slop (~> 3.4)
|
23
25
|
rake (10.5.0)
|
24
26
|
rb-fsevent (0.10.3)
|
25
|
-
rb-inotify (0.10.
|
27
|
+
rb-inotify (0.10.1)
|
26
28
|
ffi (~> 1.0)
|
27
29
|
ripper-tags (0.8.0)
|
28
30
|
rspec (3.9.0)
|
data/README.md
CHANGED
@@ -14,16 +14,82 @@ $ gem install tagrity
|
|
14
14
|
tagrity start
|
15
15
|
```
|
16
16
|
|
17
|
-
That's it!
|
17
|
+
That's it! It will monitor pwd and by default only index files tracked by git.
|
18
|
+
|
19
|
+
To stop watching pwd, use
|
20
|
+
|
21
|
+
```sh
|
22
|
+
tagrity stop
|
23
|
+
```
|
24
|
+
|
25
|
+
To view directories being watched, use
|
26
|
+
|
27
|
+
```sh
|
28
|
+
tagrity status
|
29
|
+
```
|
30
|
+
|
31
|
+
## Configuration
|
32
|
+
|
33
|
+
Configuration can be done through use of a `tagrity_config.yml` file that looks like the following:
|
34
|
+
|
35
|
+
[`tagrity_config.yml`](https://github.com/RRethy/tagrity/blob/master/sample_config.yml)
|
36
|
+
|
37
|
+
```yaml
|
38
|
+
# which command to use to generate tags for a specific file extension
|
39
|
+
# overrides default_command
|
40
|
+
# commands must support --append, -f, -L
|
41
|
+
# DEFAULT: empty
|
42
|
+
extension_commands:
|
43
|
+
rb: ripper-tags
|
44
|
+
c: ctags
|
45
|
+
go: gotags
|
46
|
+
|
47
|
+
# default command to generate tags
|
48
|
+
# command must support --append, -f, -L
|
49
|
+
# DEFAULT: ctags
|
50
|
+
default_command: ctags
|
51
|
+
|
52
|
+
# filename (relative to pwd) to generate tags into
|
53
|
+
# DEFAULT: tags
|
54
|
+
tagf: tags
|
55
|
+
|
56
|
+
# list of extensions to exclusively generate tags for
|
57
|
+
# this will take precendence over extensions_blacklist if it is non-empty
|
58
|
+
# DEFAULT: []
|
59
|
+
extensions_whitelist: [rb, c, h, js]
|
60
|
+
|
61
|
+
# list of extensions to not generate tags for
|
62
|
+
# this can will be ignored if extensions_whitelist is non-empty
|
63
|
+
# DEFAULT: []
|
64
|
+
extensions_blacklist: [erb, html, txt]
|
65
|
+
|
66
|
+
# how to integrate with git
|
67
|
+
# git_strategy: TRACKED | IGNORED | NA
|
68
|
+
# TRACKED: only index files tracked by git
|
69
|
+
# IGNORED: don't index files which are ignored by git
|
70
|
+
# NA: don't use git, index all files under pwd
|
71
|
+
#
|
72
|
+
# DEFAULT: TRACKED
|
73
|
+
git_strategy: TRACKED
|
74
|
+
|
75
|
+
# which paths (relative to pwd) to ignore
|
76
|
+
# It's usually better to avoid this since tagrity integrates with git by
|
77
|
+
# default using the strategy specified by git_strategy
|
78
|
+
# DEFAULT: []
|
79
|
+
excluded_paths: [vendor, node_modules]
|
80
|
+
```
|
81
|
+
|
82
|
+
Tagrity will look for a global config file at `$XDG_CONFIG_HOME/tagrity/tagrity_config.yml` (usually this will be `~/.config/tagrity/tagrity_config.yml`). This can be overridden by a local config file by the same name under pwd.
|
18
83
|
|
19
84
|
## Usage
|
20
85
|
|
21
86
|
```
|
22
87
|
Commands:
|
23
88
|
tagrity help [COMMAND] # Describe available commands or one specific command
|
24
|
-
tagrity
|
89
|
+
tagrity logs # Print the logs for pwd
|
90
|
+
tagrity start # Start watching pwd
|
25
91
|
tagrity status # List running tagrity processes and the directories being watched
|
26
|
-
tagrity stop # Stop watching
|
92
|
+
tagrity stop # Stop watching pwd
|
27
93
|
```
|
28
94
|
|
29
95
|
### start
|
@@ -33,15 +99,10 @@ Usage:
|
|
33
99
|
tagrity start
|
34
100
|
|
35
101
|
Options:
|
36
|
-
[--
|
37
|
-
[--
|
38
|
-
|
39
|
-
|
40
|
-
[--default-cmd=DEFAULT_CMD]
|
41
|
-
[--excluded-exts=one two three]
|
42
|
-
[--excluded-paths=one two three]
|
43
|
-
|
44
|
-
Start watching a directory (default to pwd)
|
102
|
+
[--fg], [--no-fg] # keep the tagrity process running in the foreground
|
103
|
+
[--fresh], [--no-fresh] # index the whole codebase before watching the file system. This will be slow if the codebase is large.
|
104
|
+
|
105
|
+
Start watching pwd
|
45
106
|
```
|
46
107
|
|
47
108
|
### stop
|
@@ -50,10 +111,7 @@ Start watching a directory (default to pwd)
|
|
50
111
|
Usage:
|
51
112
|
tagrity stop
|
52
113
|
|
53
|
-
|
54
|
-
[--dir=DIR]
|
55
|
-
|
56
|
-
Stop watching a directory (default to pwd)
|
114
|
+
Stop watching pwd
|
57
115
|
```
|
58
116
|
|
59
117
|
### status
|
@@ -65,15 +123,22 @@ Usage:
|
|
65
123
|
List running tagrity processes and the directories being watched
|
66
124
|
```
|
67
125
|
|
68
|
-
|
126
|
+
### logs
|
69
127
|
|
70
|
-
|
128
|
+
```
|
129
|
+
Usage:
|
130
|
+
tagrity logs
|
71
131
|
|
72
|
-
|
132
|
+
Options:
|
133
|
+
[-n=N] # the number of log lines to print
|
134
|
+
# Default: 10
|
135
|
+
|
136
|
+
Print the logs for pwd
|
137
|
+
```
|
73
138
|
|
74
139
|
## Contributing
|
75
140
|
|
76
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
141
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/RRethy/tagrity. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
77
142
|
|
78
143
|
## License
|
79
144
|
|
@@ -81,13 +146,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
81
146
|
|
82
147
|
## Code of Conduct
|
83
148
|
|
84
|
-
Everyone interacting in the Tagrity project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
tagrity config to use (default to ~/.config/tagrity/config.yml if available).
|
90
|
-
A config file is a yaml file with the following possible values.
|
91
|
-
Some of these can be overridden with options, however the configfile
|
92
|
-
provided via --configfile will override the global config file in
|
93
|
-
~/.config/tagrity/config.yml
|
149
|
+
Everyone interacting in the Tagrity project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/RRethy/tagrity/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/tagrity/cli.rb
CHANGED
@@ -2,29 +2,20 @@ require 'thor'
|
|
2
2
|
require 'tagrity/commands/start'
|
3
3
|
require 'tagrity/commands/stop'
|
4
4
|
require 'tagrity/commands/status'
|
5
|
+
require 'tagrity/commands/logs'
|
5
6
|
|
6
7
|
module Tagrity
|
7
8
|
class CLI < Thor
|
8
|
-
desc "start", "Start watching
|
9
|
-
option :
|
10
|
-
option :tagf, desc: "filename (relative) to generate tags into (default: 'tags')."
|
11
|
-
option :fg, type: :boolean, desc: "keep the tagrity process running in the foreground"
|
9
|
+
desc "start", "Start watching pwd"
|
10
|
+
option :fg, type: :boolean, default: false, desc: "keep the tagrity process running in the foreground"
|
12
11
|
option :fresh, type: :boolean, default: false, desc: "index the whole codebase before watching the file system. This will be slow if the codebase is large."
|
13
|
-
option :git, type: :boolean, default: true, desc: "only index files which are being tracked by git"
|
14
|
-
option :configfile, desc: "See README for more info."
|
15
|
-
option :ext_cmds, type: :hash, desc: "which <command> to use to generate tags based on the file extension. <command> must support -f and --append"
|
16
|
-
option :default_cmd, desc: "the default <command> to be used to generate tags (default: 'ctags'). <command> must support -f and --append"
|
17
|
-
option :excluded_exts, type: :array, desc: "which file extensions to not generate tags for."
|
18
|
-
option :excluded_paths, type: :array, desc: "which paths to ignore. Usually better to ignore this since by default only file tracked by git are indexed."
|
19
12
|
def start()
|
20
|
-
|
21
|
-
Command::Start::call(dir, fg?, fresh?)
|
13
|
+
Command::Start::call(options['fg'], options['fresh'])
|
22
14
|
end
|
23
15
|
|
24
|
-
desc "stop", "Stop watching
|
25
|
-
option :dir
|
16
|
+
desc "stop", "Stop watching pwd"
|
26
17
|
def stop()
|
27
|
-
Command::Stop::call
|
18
|
+
Command::Stop::call
|
28
19
|
end
|
29
20
|
|
30
21
|
desc "status", "List running tagrity processes and the directories being watched"
|
@@ -32,32 +23,10 @@ module Tagrity
|
|
32
23
|
Command::Status::call
|
33
24
|
end
|
34
25
|
|
35
|
-
|
36
|
-
|
37
|
-
def
|
38
|
-
|
39
|
-
raise Errno::ENOENT, "No such directory - #{dir}" unless Dir.exists?(dir)
|
40
|
-
dir
|
41
|
-
end
|
42
|
-
|
43
|
-
def fg?
|
44
|
-
options[:fg]
|
45
|
-
end
|
46
|
-
|
47
|
-
def fresh?
|
48
|
-
options[:fresh]
|
49
|
-
end
|
50
|
-
|
51
|
-
def setup_config
|
52
|
-
ConfigFile.instance.init(
|
53
|
-
configfile: options[:configfile],
|
54
|
-
default_cmd: options[:default_cmd],
|
55
|
-
tagf: options[:tagf],
|
56
|
-
ext_cmds: options[:ext_cmds],
|
57
|
-
excluded_exts: options[:excluded_exts],
|
58
|
-
excluded_paths: options[:excluded_paths],
|
59
|
-
git: options[:git]
|
60
|
-
)
|
26
|
+
desc "logs", "Print the logs for pwd"
|
27
|
+
option :n, type: :numeric, default: 10, desc: "the number of log lines to print"
|
28
|
+
def logs
|
29
|
+
Command::Logs::call(options['n'])
|
61
30
|
end
|
62
31
|
end
|
63
32
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'tagrity/tlogger'
|
2
|
+
|
3
|
+
module Tagrity
|
4
|
+
module Command
|
5
|
+
class Logs
|
6
|
+
class << self
|
7
|
+
def call(n)
|
8
|
+
if File.readable?(logf)
|
9
|
+
puts `cat #{logf} | tail -n #{Integer(n)}`.split("\n")
|
10
|
+
else
|
11
|
+
puts "Error: There doesn't seem to be a log file for #{Dir.pwd}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def logf
|
18
|
+
Tlogger.instance.logf
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'listen'
|
2
|
+
require 'cli/ui'
|
2
3
|
require 'tagrity/pid_file'
|
3
4
|
require 'tagrity/helper'
|
4
|
-
require 'tagrity/file_callbacks'
|
5
5
|
require 'tagrity/provider'
|
6
|
+
require 'tagrity/tlogger'
|
6
7
|
|
7
8
|
module Tagrity
|
8
9
|
module Command
|
@@ -10,32 +11,47 @@ module Tagrity
|
|
10
11
|
class ErrorProcessAlreadyRunning < StandardError; end
|
11
12
|
|
12
13
|
class << self
|
13
|
-
def call(
|
14
|
+
def call(fg, fresh)
|
15
|
+
dir = Dir.pwd
|
14
16
|
assert_not_running(dir)
|
15
17
|
|
16
18
|
Process.daemon(nochdir: true) unless fg
|
17
19
|
|
18
|
-
|
20
|
+
tag_generator = Provider.provide(:tag_generator)
|
19
21
|
PidFile.write(PidFile.new(dir, Process.pid))
|
20
22
|
|
21
|
-
|
23
|
+
logger.fg = fg
|
24
|
+
logger.info("Watching #{dir} with process pid #{Process.pid}")
|
25
|
+
|
26
|
+
if fresh
|
27
|
+
logger.info("Generating tags fresh for #{dir}")
|
28
|
+
tag_generator.generate_all
|
29
|
+
end
|
22
30
|
|
23
31
|
listener = Listen.to(
|
24
32
|
dir,
|
25
33
|
relative: true,
|
26
34
|
) do |modified, added, removed|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
unless modified.empty?
|
36
|
+
logger.info("modified absolute path: #{modified}")
|
37
|
+
tag_generator.generate(modified)
|
38
|
+
end
|
39
|
+
unless added.empty?
|
40
|
+
logger.info("added absolute path: #{added}")
|
41
|
+
tag_generator.generate(added)
|
42
|
+
end
|
43
|
+
unless removed.empty?
|
44
|
+
logger.info("removed absolute path: #{removed}")
|
45
|
+
tag_generator.delete_files_tags(removed)
|
46
|
+
end
|
33
47
|
end
|
34
48
|
listener.start
|
35
49
|
sleep
|
36
50
|
rescue ErrorProcessAlreadyRunning => e
|
37
|
-
puts e.message
|
51
|
+
puts ::CLI::UI.fmt "{{red:#{e.message}}}"
|
52
|
+
logger.error(e.message)
|
38
53
|
rescue Interrupt => e
|
54
|
+
logger.info("Process interrupted. Killing #{Process.pid}")
|
39
55
|
PidFile.delete(dir)
|
40
56
|
end
|
41
57
|
|
@@ -48,6 +64,10 @@ module Tagrity
|
|
48
64
|
raise ErrorProcessAlreadyRunning, "Error: tagrity is already watching #{dir} with process #{pids}"
|
49
65
|
end
|
50
66
|
end
|
67
|
+
|
68
|
+
def logger
|
69
|
+
@logger ||= Tlogger.instance
|
70
|
+
end
|
51
71
|
end
|
52
72
|
end
|
53
73
|
end
|
@@ -1,10 +1,25 @@
|
|
1
|
+
require 'cli/ui'
|
2
|
+
|
1
3
|
module Tagrity
|
2
4
|
module Command
|
3
5
|
class Status
|
4
6
|
class << self
|
5
7
|
def call
|
6
|
-
PidFile.alive_pid_files.each do |pid_file|
|
7
|
-
|
8
|
+
pid_files = PidFile.alive_pid_files.each do |pid_file|
|
9
|
+
pid_file
|
10
|
+
end
|
11
|
+
|
12
|
+
return if pid_files.empty?
|
13
|
+
|
14
|
+
max_pid_len = pid_files.max do |a, b|
|
15
|
+
a.pid.digits.count <=> b.pid.digits.count
|
16
|
+
end.pid.digits.count
|
17
|
+
max_dir_len = pid_files.max do |a, b|
|
18
|
+
a.dir.length <=> b.dir.length
|
19
|
+
end.dir.length
|
20
|
+
|
21
|
+
pid_files.each do |pid_file|
|
22
|
+
puts ::CLI::UI.fmt "{{cyan:#{pid_file.pid.to_s.ljust(max_pid_len)}}} {{green:#{pid_file.dir.ljust(max_dir_len)}}}"
|
8
23
|
end
|
9
24
|
end
|
10
25
|
end
|
@@ -1,15 +1,20 @@
|
|
1
|
+
require 'cli/ui'
|
2
|
+
require 'tagrity/tlogger'
|
3
|
+
|
1
4
|
module Tagrity
|
2
5
|
module Command
|
3
6
|
class Stop
|
4
7
|
class << self
|
5
|
-
def call
|
8
|
+
def call
|
9
|
+
dir = Dir.pwd
|
6
10
|
pid_files = PidFile.alive_pid_files(dir: dir)
|
7
11
|
if pid_files.empty?
|
8
|
-
puts "😕 tagrity doesn't seem to be watching #{dir}"
|
12
|
+
puts ::CLI::UI.fmt "{{red:#{"😕 tagrity doesn't seem to be watching #{dir}"}}}"
|
9
13
|
else
|
10
14
|
pid_files.each do |pid_file|
|
11
15
|
pid_file.delete
|
12
|
-
puts "Successfully killed #{pid_file.pid}"
|
16
|
+
puts ::CLI::UI.fmt "{{green:#{"Successfully killed #{pid_file.pid}"}}}"
|
17
|
+
Tlogger.instance.info("Successfully killed #{pid_file.pid}")
|
13
18
|
end
|
14
19
|
end
|
15
20
|
end
|
data/lib/tagrity/config_file.rb
CHANGED
@@ -7,105 +7,129 @@ module Tagrity
|
|
7
7
|
include Singleton
|
8
8
|
|
9
9
|
class ErrorTagFileNotWritable < StandardError; end
|
10
|
-
class ErrorGitNotExecutable < StandardError; end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
11
|
+
CONFIG_FNAME = 'tagrity_config.yml'
|
12
|
+
LOCAL_CONFIG_PATH = File.expand_path("./.#{CONFIG_FNAME}")
|
13
|
+
GLOBAL_CONFIG_PATH = File.expand_path("#{ENV['XDG_CONFIG_HOME'] || "#{ENV['HOME']}/.config"}/tagrity/#{CONFIG_FNAME}")
|
14
|
+
|
15
|
+
def init
|
16
|
+
ensure_extension_commands
|
17
|
+
ensure_default_command
|
18
|
+
ensure_tagf
|
19
|
+
ensure_extensions_whitelist
|
20
|
+
ensure_extensions_blacklist
|
21
|
+
ensure_git_strategy
|
22
|
+
ensure_excluded_paths
|
23
|
+
end
|
24
|
+
|
25
|
+
def command_for_extension(extension)
|
26
|
+
cmd = extension_commands[extension]
|
27
|
+
if cmd.nil?
|
28
|
+
default_command
|
29
|
+
else
|
30
|
+
cmd
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def ignore_extension?(extension)
|
35
|
+
unless extensions_whitelist.empty?
|
36
|
+
return !extensions_whitelist.include?(extension)
|
37
|
+
end
|
38
|
+
|
39
|
+
extensions_blacklist.include?(extension)
|
29
40
|
end
|
30
41
|
|
31
|
-
def
|
32
|
-
|
33
|
-
return @config['default_cmd'] if ft_cmd.nil? || !Helper.is_executable?(ft_cmd)
|
34
|
-
ft_cmd
|
42
|
+
def path_ignored?(path)
|
43
|
+
excluded_paths.any? { |pat| /#{pat}/ =~ path }
|
35
44
|
end
|
36
45
|
|
37
|
-
def
|
38
|
-
|
46
|
+
def respect_git?
|
47
|
+
git_strategy != 'NA'
|
39
48
|
end
|
40
49
|
|
41
|
-
def
|
42
|
-
|
50
|
+
def extension_commands
|
51
|
+
config['extension_commands']
|
52
|
+
end
|
53
|
+
|
54
|
+
def default_command
|
55
|
+
config['default_command']
|
43
56
|
end
|
44
57
|
|
45
58
|
def tagf
|
46
|
-
|
59
|
+
config['tagf']
|
47
60
|
end
|
48
61
|
|
49
|
-
def
|
50
|
-
|
62
|
+
def extensions_whitelist
|
63
|
+
config['extensions_whitelist']
|
64
|
+
end
|
65
|
+
|
66
|
+
def extensions_blacklist
|
67
|
+
config['extensions_blacklist']
|
68
|
+
end
|
69
|
+
|
70
|
+
def git_strategy
|
71
|
+
config['git_strategy']
|
72
|
+
end
|
73
|
+
|
74
|
+
def excluded_paths
|
75
|
+
config['excluded_paths']
|
51
76
|
end
|
52
77
|
|
53
78
|
def to_s
|
54
|
-
|
79
|
+
config.to_s
|
55
80
|
end
|
56
81
|
|
57
82
|
private
|
58
83
|
|
59
|
-
def
|
60
|
-
|
84
|
+
def ensure_extension_commands
|
85
|
+
ensure_option('extension_commands', {})
|
61
86
|
end
|
62
87
|
|
63
|
-
def
|
64
|
-
|
88
|
+
def ensure_default_command
|
89
|
+
ensure_option('default_command', 'ctags')
|
65
90
|
end
|
66
91
|
|
67
|
-
def
|
68
|
-
|
92
|
+
def ensure_tagf
|
93
|
+
ensure_option('tagf', 'tags')
|
94
|
+
if File.exists?(tagf) && !File.writable?(tagf)
|
95
|
+
raise ErrorTagFileNotWritable, "#{tagf} must be writable to be used as the tag file."
|
96
|
+
end
|
69
97
|
end
|
70
98
|
|
71
|
-
def
|
72
|
-
|
99
|
+
def ensure_extensions_whitelist
|
100
|
+
ensure_option('whitelist_extensions', [])
|
73
101
|
end
|
74
102
|
|
75
|
-
def
|
76
|
-
|
77
|
-
if File.exists?(@config['tagf']) && !File.writable?(@config['tagf'])
|
78
|
-
raise ErrorTagFileNotWritable, "#{@config['tagf']} must be writable to be used as the tag file."
|
79
|
-
end
|
103
|
+
def ensure_extensions_blacklist
|
104
|
+
ensure_option('blacklist_extensions', [])
|
80
105
|
end
|
81
106
|
|
82
|
-
def
|
83
|
-
|
84
|
-
if @config['git'] && !Helper.is_executable?('git')
|
85
|
-
raise ErrorGitNotExecutable, "'git' must be executable to use the --git option."
|
86
|
-
end
|
107
|
+
def ensure_git_strategy
|
108
|
+
ensure_option('git_strategy', 'TRACKED')
|
87
109
|
end
|
88
110
|
|
89
|
-
def
|
90
|
-
|
91
|
-
@config[key] = local_val
|
92
|
-
end
|
93
|
-
return if @config.key?(key) && !@config[key].nil? && @config[key].is_a?(default.class)
|
94
|
-
@config[key] = default
|
111
|
+
def ensure_excluded_paths
|
112
|
+
ensure_option('extension_commands', [])
|
95
113
|
end
|
96
114
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
|
115
|
+
def ensure_option(name, default)
|
116
|
+
if config[name].nil? || !config[name].is_a?(default.class)
|
117
|
+
config[name] = default
|
118
|
+
end
|
101
119
|
end
|
102
120
|
|
103
|
-
def
|
104
|
-
|
121
|
+
def config
|
122
|
+
@config ||= read_config
|
105
123
|
end
|
106
124
|
|
107
|
-
def
|
108
|
-
|
125
|
+
def read_config
|
126
|
+
if File.readable?(LOCAL_CONFIG_PATH)
|
127
|
+
@config = YAML.load_file(LOCAL_CONFIG_PATH)
|
128
|
+
elsif File.readable?(GLOBAL_CONFIG_PATH)
|
129
|
+
@config = YAML.load_file(GLOBAL_CONFIG_PATH)
|
130
|
+
else
|
131
|
+
@config = {}
|
132
|
+
end
|
109
133
|
end
|
110
134
|
end
|
111
135
|
end
|
data/lib/tagrity/helper.rb
CHANGED
@@ -10,6 +10,11 @@ module Tagrity
|
|
10
10
|
RUN_DIR
|
11
11
|
end
|
12
12
|
|
13
|
+
def log_dir
|
14
|
+
ensure_data_dirs
|
15
|
+
LOG_DIR
|
16
|
+
end
|
17
|
+
|
13
18
|
def is_executable?(cmd)
|
14
19
|
!%x{command -v #{cmd}}.empty?
|
15
20
|
end
|
@@ -28,21 +33,16 @@ module Tagrity
|
|
28
33
|
end
|
29
34
|
|
30
35
|
def is_git_dir?
|
31
|
-
return @is_git_dir unless @is_git_dir.nil?
|
32
36
|
`git rev-parse --git-dir &> /dev/null`
|
33
|
-
|
34
|
-
@is_git_dir = true
|
35
|
-
else
|
36
|
-
@is_git_dir = false
|
37
|
-
end
|
37
|
+
$?.exitstatus == 0
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def file_ignored?(file)
|
41
41
|
`git check-ignore -q #{file} &> /dev/null`
|
42
42
|
$?.exitstatus == 0
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def file_tracked?(file)
|
46
46
|
`git ls-files --error-unmatch #{file} &> /dev/null`
|
47
47
|
$?.exitstatus == 0
|
48
48
|
end
|
@@ -51,6 +51,7 @@ module Tagrity
|
|
51
51
|
|
52
52
|
def ensure_data_dirs
|
53
53
|
FileUtils.mkdir_p(RUN_DIR)
|
54
|
+
FileUtils.mkdir_p(LOG_DIR)
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
data/lib/tagrity/provider.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'tagrity/file_callbacks'
|
2
1
|
require 'tagrity/config_file'
|
3
2
|
require 'tagrity/tag_generator'
|
4
3
|
|
@@ -7,17 +6,11 @@ module Tagrity
|
|
7
6
|
class << self
|
8
7
|
def provide(want)
|
9
8
|
case want
|
10
|
-
when :file_callbacks
|
11
|
-
provide_file_callbacks
|
12
9
|
when :tag_generator
|
13
10
|
provide_tag_generator
|
14
11
|
end
|
15
12
|
end
|
16
13
|
|
17
|
-
def provide_file_callbacks
|
18
|
-
FileCallbacks.new(provide(:tag_generator))
|
19
|
-
end
|
20
|
-
|
21
14
|
def provide_tag_generator
|
22
15
|
TagGenerator.new
|
23
16
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'tmpdir'
|
2
2
|
require 'tempfile'
|
3
3
|
require 'fileutils'
|
4
|
-
require 'pry'
|
5
4
|
require 'tagrity/helper'
|
5
|
+
require 'tagrity/tlogger'
|
6
6
|
|
7
7
|
module Tagrity
|
8
8
|
class TagGenerator
|
@@ -17,15 +17,16 @@ module Tagrity
|
|
17
17
|
if File.exists?(tagf)
|
18
18
|
File.delete(tagf)
|
19
19
|
end
|
20
|
-
if check_git?
|
21
|
-
|
20
|
+
cmd = if check_git?
|
21
|
+
'git ls-files 2> /dev/null'
|
22
22
|
else
|
23
|
-
|
23
|
+
'find * 2> /dev/null'
|
24
24
|
end
|
25
|
+
files = `#{cmd}`.split("\n")
|
25
26
|
if $?.exitstatus == 0
|
26
27
|
generate(files)
|
27
28
|
else
|
28
|
-
|
29
|
+
logger.error("Failed to get a listing of all files under pwd for use with --fresh. Used #{cmd}.")
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
@@ -33,15 +34,15 @@ module Tagrity
|
|
33
34
|
return if files.empty?
|
34
35
|
files
|
35
36
|
.select { |file| generate_tags?(file) }
|
36
|
-
.group_by { |file| @config.
|
37
|
+
.group_by { |file| @config.command_for_extension(file.partition('.').last) }
|
37
38
|
.each do |cmd, fnames|
|
38
39
|
Tempfile.create do |tmpf|
|
39
40
|
IO::write(tmpf.path, fnames.join("\n"))
|
40
41
|
system(cmd, '-f', tagf, '--append', '-L', tmpf.path, out: File::NULL)
|
41
42
|
if $?.exitstatus == 0
|
42
|
-
|
43
|
+
logger.info("{#{cmd}} generated tags for #{fnames} into #{tagf}")
|
43
44
|
else
|
44
|
-
|
45
|
+
logger.info("{#{cmd}} failed to generate tags for #{fnames} into #{tagf}")
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
@@ -59,7 +60,7 @@ module Tagrity
|
|
59
60
|
end
|
60
61
|
tmpf.rewind
|
61
62
|
FileUtils.mv(tmpf.path, tagf, force: true)
|
62
|
-
|
63
|
+
logger.info("Deleted tags for #{files} from #{tagf}")
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
@@ -74,7 +75,15 @@ module Tagrity
|
|
74
75
|
end
|
75
76
|
|
76
77
|
def copacetic_with_git?(file)
|
77
|
-
|
78
|
+
return true if !check_git?
|
79
|
+
case @config.git_strategy
|
80
|
+
when 'TRACKED'
|
81
|
+
Helper.file_tracked?(file)
|
82
|
+
when 'IGNORED'
|
83
|
+
!Helper.file_ignored?(file)
|
84
|
+
else
|
85
|
+
false
|
86
|
+
end
|
78
87
|
end
|
79
88
|
|
80
89
|
def check_git?
|
@@ -82,7 +91,7 @@ module Tagrity
|
|
82
91
|
end
|
83
92
|
|
84
93
|
def is_file_excluded(fname)
|
85
|
-
@config.
|
94
|
+
@config.ignore_extension?(fname.partition('.').last) || @config.path_ignored?(fname)
|
86
95
|
end
|
87
96
|
|
88
97
|
def assert_executables
|
@@ -96,5 +105,9 @@ module Tagrity
|
|
96
105
|
def tagf
|
97
106
|
@config.tagf
|
98
107
|
end
|
108
|
+
|
109
|
+
def logger
|
110
|
+
Tlogger.instance
|
111
|
+
end
|
99
112
|
end
|
100
113
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'logger'
|
3
|
+
require 'tagrity/helper'
|
4
|
+
|
5
|
+
module Tagrity
|
6
|
+
class Tlogger
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
attr_writer :fg
|
10
|
+
|
11
|
+
def info(msg)
|
12
|
+
logger.info(msg)
|
13
|
+
end
|
14
|
+
|
15
|
+
def error(msg)
|
16
|
+
logger.error(msg)
|
17
|
+
end
|
18
|
+
|
19
|
+
def logf
|
20
|
+
# TODO this can cause duplicates, unlikely tho
|
21
|
+
"#{Helper.log_dir}/#{Dir.pwd.gsub(/\//, '--')}.log"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def logger
|
27
|
+
@logger ||= Logger.new(@fg ? STDOUT : logf, 'weekly')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/tagrity/version.rb
CHANGED
data/sample_config.yml
CHANGED
@@ -1,31 +1,42 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# <file extension>: <command to use to generate tags for this file extension>
|
1
|
+
# which command to use to generate tags for a specific file extension
|
2
|
+
# overrides default_command
|
3
|
+
# commands must support --append, -f, -L
|
5
4
|
# DEFAULT: empty
|
6
|
-
|
5
|
+
extension_commands:
|
7
6
|
rb: ripper-tags
|
8
7
|
c: ctags
|
9
8
|
go: gotags
|
10
9
|
|
11
|
-
#
|
12
|
-
#
|
10
|
+
# default command to generate tags
|
11
|
+
# command must support --append, -f, -L
|
13
12
|
# DEFAULT: ctags
|
14
|
-
|
13
|
+
default_command: ctags
|
15
14
|
|
16
|
-
#
|
17
|
-
# tagf: <filename>
|
15
|
+
# filename (relative to pwd) to generate tags into
|
18
16
|
# DEFAULT: tags
|
19
17
|
tagf: tags
|
20
18
|
|
21
|
-
#
|
22
|
-
#
|
19
|
+
# list of extensions to exclusively generate tags for
|
20
|
+
# this will take precendence over extensions_blacklist if it is non-empty
|
23
21
|
# DEFAULT: []
|
24
|
-
|
22
|
+
extensions_whitelist: [rb, c, h, js]
|
25
23
|
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
24
|
+
# list of extensions to not generate tags for
|
25
|
+
# this can will be ignored if extensions_whitelist is non-empty
|
26
|
+
# DEFAULT: []
|
27
|
+
extensions_blacklist: [erb, html, txt]
|
28
|
+
|
29
|
+
# how to integrate with git
|
30
|
+
# git_strategy: TRACKED | IGNORED | NA
|
31
|
+
# TRACKED: only index files tracked by git
|
32
|
+
# IGNORED: don't index files which are ignored by git
|
33
|
+
# NA: don't use git, index all files under pwd
|
34
|
+
#
|
35
|
+
# DEFAULT: TRACKED
|
36
|
+
git_strategy: TRACKED
|
37
|
+
|
38
|
+
# which paths (relative to pwd) to ignore
|
39
|
+
# It's usually better to avoid this since tagrity integrates with git by
|
40
|
+
# default using the strategy specified by git_strategy
|
30
41
|
# DEFAULT: []
|
31
42
|
excluded_paths: [vendor, node_modules]
|
data/tagrity.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
spec.add_dependency 'thor', '~> 0.20'
|
30
30
|
spec.add_dependency 'listen', '~> 3.0'
|
31
|
+
spec.add_dependency 'cli-ui', '~> 1.3.0'
|
31
32
|
|
32
33
|
spec.add_development_dependency "bundler", "~> 2.0"
|
33
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tagrity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam P. Regasz-Rethy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cli-ui
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.3.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.3.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,7 +130,6 @@ executables:
|
|
116
130
|
extensions: []
|
117
131
|
extra_rdoc_files: []
|
118
132
|
files:
|
119
|
-
- ".byebug_history"
|
120
133
|
- ".gitignore"
|
121
134
|
- ".rspec"
|
122
135
|
- ".travis.yml"
|
@@ -131,15 +144,16 @@ files:
|
|
131
144
|
- exe/tagrity
|
132
145
|
- lib/tagrity.rb
|
133
146
|
- lib/tagrity/cli.rb
|
147
|
+
- lib/tagrity/commands/logs.rb
|
134
148
|
- lib/tagrity/commands/start.rb
|
135
149
|
- lib/tagrity/commands/status.rb
|
136
150
|
- lib/tagrity/commands/stop.rb
|
137
151
|
- lib/tagrity/config_file.rb
|
138
|
-
- lib/tagrity/file_callbacks.rb
|
139
152
|
- lib/tagrity/helper.rb
|
140
153
|
- lib/tagrity/pid_file.rb
|
141
154
|
- lib/tagrity/provider.rb
|
142
155
|
- lib/tagrity/tag_generator.rb
|
156
|
+
- lib/tagrity/tlogger.rb
|
143
157
|
- lib/tagrity/version.rb
|
144
158
|
- sample_config.yml
|
145
159
|
- tagrity.gemspec
|
@@ -165,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
179
|
- !ruby/object:Gem::Version
|
166
180
|
version: '0'
|
167
181
|
requirements: []
|
168
|
-
rubygems_version: 3.0.
|
182
|
+
rubygems_version: 3.0.6
|
169
183
|
signing_key:
|
170
184
|
specification_version: 4
|
171
185
|
summary: Regenerate tags on file changes.
|
data/.byebug_history
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'tagrity/tag_generator'
|
2
|
-
require 'tagrity/config_file'
|
3
|
-
|
4
|
-
module Tagrity
|
5
|
-
class FileCallbacks
|
6
|
-
def initialize(tag_generator)
|
7
|
-
@tag_generator = tag_generator
|
8
|
-
end
|
9
|
-
|
10
|
-
def on_fresh
|
11
|
-
@tag_generator.generate_all
|
12
|
-
end
|
13
|
-
|
14
|
-
def on_files_modified(files)
|
15
|
-
@tag_generator.generate(files)
|
16
|
-
end
|
17
|
-
|
18
|
-
def on_files_added(files)
|
19
|
-
@tag_generator.generate(files)
|
20
|
-
end
|
21
|
-
|
22
|
-
def on_files_removed(files)
|
23
|
-
@tag_generator.delete_files_tags(files)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|