tagrity 0.1.1 → 0.1.6
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 +4 -4
- data/.byebug_history +4 -0
- data/Gemfile.lock +12 -2
- data/README.md +62 -12
- data/lib/tagrity/cli.rb +31 -14
- data/lib/tagrity/commands/start.rb +10 -8
- data/lib/tagrity/config_file.rb +105 -1
- data/lib/tagrity/file_callbacks.rb +7 -2
- data/lib/tagrity/helper.rb +57 -0
- data/lib/tagrity/pid_file.rb +9 -20
- data/lib/tagrity/provider.rb +26 -0
- data/lib/tagrity/tag_generator.rb +77 -4
- data/lib/tagrity/version.rb +1 -1
- data/sample_config.yml +31 -0
- data/tagrity.gemspec +2 -0
- metadata +34 -4
- data/lib/tagrity/commands/restart.rb +0 -12
- data/lib/tagrity/process_helper.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bbba0199d2e4305cc015fc1bf2151892628224fdb31ad0a1b2fe0e08b2a5b8b
|
4
|
+
data.tar.gz: b2910418b53ce0d188c03048ca4554988e1833269ed385a041291dd0427a4499
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d103e833875ab1d827dc26857a78c9795092ccf1fd8d346fa506fcf3586b6581d5842a6d5a30b9ea470643997a97722e9df922b83cdbd8a1607b222261eaa114
|
7
|
+
data.tar.gz: 24eef3ae46b97b8e56802013a60217e9c8749f81846e4beff6f056f33166e9f2d4935cc4a12f6c8005d5b93d29db9d5803fef18e586f5cd3a8d82faf5b0a7392
|
data/.byebug_history
ADDED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tagrity (0.1.
|
4
|
+
tagrity (0.1.6)
|
5
5
|
listen (~> 3.0)
|
6
|
+
pry (~> 0.9.9)
|
6
7
|
thor (~> 0.20)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
12
|
+
coderay (1.1.2)
|
11
13
|
diff-lcs (1.3)
|
12
14
|
ffi (1.11.3)
|
13
|
-
listen (3.2.
|
15
|
+
listen (3.2.1)
|
14
16
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
15
17
|
rb-inotify (~> 0.9, >= 0.9.10)
|
18
|
+
method_source (0.9.2)
|
19
|
+
pry (0.9.12.6)
|
20
|
+
coderay (~> 1.0)
|
21
|
+
method_source (~> 0.8)
|
22
|
+
slop (~> 3.4)
|
16
23
|
rake (10.5.0)
|
17
24
|
rb-fsevent (0.10.3)
|
18
25
|
rb-inotify (0.10.0)
|
19
26
|
ffi (~> 1.0)
|
27
|
+
ripper-tags (0.8.0)
|
20
28
|
rspec (3.9.0)
|
21
29
|
rspec-core (~> 3.9.0)
|
22
30
|
rspec-expectations (~> 3.9.0)
|
@@ -30,6 +38,7 @@ GEM
|
|
30
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
39
|
rspec-support (~> 3.9.0)
|
32
40
|
rspec-support (3.9.0)
|
41
|
+
slop (3.6.0)
|
33
42
|
thor (0.20.3)
|
34
43
|
|
35
44
|
PLATFORMS
|
@@ -38,6 +47,7 @@ PLATFORMS
|
|
38
47
|
DEPENDENCIES
|
39
48
|
bundler (~> 2.0)
|
40
49
|
rake (~> 10.0)
|
50
|
+
ripper-tags (~> 0.8.0)
|
41
51
|
rspec (~> 3.0)
|
42
52
|
tagrity!
|
43
53
|
|
data/README.md
CHANGED
@@ -1,28 +1,69 @@
|
|
1
1
|
# Tagrity
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Automatically regenerate tags on file changes.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
```sh
|
8
|
+
$ gem install tagrity
|
9
|
+
```
|
10
|
+
|
11
|
+
## Quick Start
|
10
12
|
|
11
|
-
```
|
12
|
-
|
13
|
+
```sh
|
14
|
+
tagrity start
|
13
15
|
```
|
14
16
|
|
15
|
-
|
17
|
+
That's it! By default, tagrity will only index files tracked by git. You may wish to al
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```
|
22
|
+
Commands:
|
23
|
+
tagrity help [COMMAND] # Describe available commands or one specific command
|
24
|
+
tagrity start # Start watching a directory (default to pwd)
|
25
|
+
tagrity status # List running tagrity processes and the directories being watched
|
26
|
+
tagrity stop # Stop watching a directory (default to pwd)
|
27
|
+
```
|
16
28
|
|
17
|
-
|
29
|
+
### start
|
18
30
|
|
19
|
-
|
31
|
+
```
|
32
|
+
Usage:
|
33
|
+
tagrity start
|
34
|
+
|
35
|
+
Options:
|
36
|
+
[--dir=DIR]
|
37
|
+
[--fg], [--no-fg]
|
38
|
+
[--configfile=CONFIGFILE]
|
39
|
+
[--tagf=TAGF]
|
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)
|
45
|
+
```
|
20
46
|
|
21
|
-
|
47
|
+
### stop
|
22
48
|
|
23
|
-
|
49
|
+
```
|
50
|
+
Usage:
|
51
|
+
tagrity stop
|
24
52
|
|
25
|
-
|
53
|
+
Options:
|
54
|
+
[--dir=DIR]
|
55
|
+
|
56
|
+
Stop watching a directory (default to pwd)
|
57
|
+
```
|
58
|
+
|
59
|
+
### status
|
60
|
+
|
61
|
+
```
|
62
|
+
Usage:
|
63
|
+
tagrity status
|
64
|
+
|
65
|
+
List running tagrity processes and the directories being watched
|
66
|
+
```
|
26
67
|
|
27
68
|
## Development
|
28
69
|
|
@@ -41,3 +82,12 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
82
|
## Code of Conduct
|
42
83
|
|
43
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/[USERNAME]/tagrity/blob/master/CODE_OF_CONDUCT.md).
|
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
|
data/lib/tagrity/cli.rb
CHANGED
@@ -1,32 +1,33 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'tagrity/commands/start'
|
3
3
|
require 'tagrity/commands/stop'
|
4
|
-
require 'tagrity/commands/restart'
|
5
4
|
require 'tagrity/commands/status'
|
6
5
|
|
7
6
|
module Tagrity
|
8
7
|
class CLI < Thor
|
9
|
-
desc "start", "Start watching
|
10
|
-
option :dir
|
11
|
-
option :
|
8
|
+
desc "start", "Start watching a directory (default to pwd)"
|
9
|
+
option :dir, desc: "directory to watch (omit to use pwd)"
|
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"
|
12
|
+
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."
|
12
19
|
def start()
|
13
|
-
|
20
|
+
setup_config
|
21
|
+
Command::Start::call(dir, fg?, fresh?)
|
14
22
|
end
|
15
23
|
|
16
|
-
desc "stop", "Stop watching
|
24
|
+
desc "stop", "Stop watching a directory (default to pwd)"
|
17
25
|
option :dir
|
18
26
|
def stop()
|
19
27
|
Command::Stop::call(dir)
|
20
28
|
end
|
21
29
|
|
22
|
-
desc "
|
23
|
-
option :dir
|
24
|
-
option :fg, type: :boolean
|
25
|
-
def restart()
|
26
|
-
Command::Restart::call(dir, fg?)
|
27
|
-
end
|
28
|
-
|
29
|
-
desc "status", "status running tagrity processes watching directories"
|
30
|
+
desc "status", "List running tagrity processes and the directories being watched"
|
30
31
|
def status
|
31
32
|
Command::Status::call
|
32
33
|
end
|
@@ -42,5 +43,21 @@ module Tagrity
|
|
42
43
|
def fg?
|
43
44
|
options[:fg]
|
44
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
|
+
)
|
61
|
+
end
|
45
62
|
end
|
46
63
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'listen'
|
2
2
|
require 'tagrity/pid_file'
|
3
|
-
require 'tagrity/
|
3
|
+
require 'tagrity/helper'
|
4
4
|
require 'tagrity/file_callbacks'
|
5
|
+
require 'tagrity/provider'
|
5
6
|
|
6
7
|
module Tagrity
|
7
8
|
module Command
|
@@ -9,25 +10,26 @@ module Tagrity
|
|
9
10
|
class ErrorProcessAlreadyRunning < StandardError; end
|
10
11
|
|
11
12
|
class << self
|
12
|
-
def call(dir, fg)
|
13
|
+
def call(dir, fg, fresh)
|
13
14
|
assert_not_running(dir)
|
14
15
|
|
15
|
-
|
16
|
+
Process.daemon(nochdir: true) unless fg
|
16
17
|
|
17
|
-
|
18
|
+
callbacks = Provider.provide(:file_callbacks)
|
18
19
|
PidFile.write(PidFile.new(dir, Process.pid))
|
19
20
|
|
21
|
+
callbacks.on_fresh if fresh
|
22
|
+
|
20
23
|
listener = Listen.to(
|
21
24
|
dir,
|
22
|
-
ignore: [/tags/],
|
23
25
|
relative: true,
|
24
26
|
) do |modified, added, removed|
|
27
|
+
puts "modified absolute path: #{modified}"
|
28
|
+
puts "added absolute path: #{added}"
|
29
|
+
puts "removed absolute path: #{removed}"
|
25
30
|
callbacks.on_files_modified(modified)
|
26
31
|
callbacks.on_files_added(added)
|
27
32
|
callbacks.on_files_removed(removed)
|
28
|
-
puts "modified absolute paths: #{modified}"
|
29
|
-
puts "added absolute paths: #{added}"
|
30
|
-
puts "removed absolute paths: #{removed}"
|
31
33
|
end
|
32
34
|
listener.start
|
33
35
|
sleep
|
data/lib/tagrity/config_file.rb
CHANGED
@@ -1,7 +1,111 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'singleton'
|
3
|
+
require 'tagrity/helper'
|
4
|
+
|
1
5
|
module Tagrity
|
2
6
|
class ConfigFile
|
3
|
-
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
class ErrorTagFileNotWritable < StandardError; end
|
10
|
+
class ErrorGitNotExecutable < StandardError; end
|
11
|
+
|
12
|
+
def init(
|
13
|
+
configfile:,
|
14
|
+
default_cmd:,
|
15
|
+
tagf:,
|
16
|
+
ext_cmds:,
|
17
|
+
excluded_exts:,
|
18
|
+
excluded_paths:,
|
19
|
+
git:
|
20
|
+
)
|
21
|
+
fname = config_file_name(configfile)
|
22
|
+
@config = if fname.nil? then {} else YAML.load_file(fname) end
|
23
|
+
ensure_ext_cmds(ext_cmds)
|
24
|
+
ensure_default_cmd(default_cmd)
|
25
|
+
ensure_tagf(tagf)
|
26
|
+
ensure_excluded_exts(excluded_exts)
|
27
|
+
ensure_excluded_paths(excluded_paths)
|
28
|
+
ensure_git(git)
|
29
|
+
end
|
30
|
+
|
31
|
+
def ft_to_cmd(ext)
|
32
|
+
ft_cmd = @config['ext_cmds'][ext]
|
33
|
+
return @config['default_cmd'] if ft_cmd.nil? || !Helper.is_executable?(ft_cmd)
|
34
|
+
ft_cmd
|
35
|
+
end
|
36
|
+
|
37
|
+
def is_ft_excluded(ext)
|
38
|
+
@config['excluded_exts'].include?(ext)
|
39
|
+
end
|
40
|
+
|
41
|
+
def is_path_excluded(path)
|
42
|
+
@config['excluded_paths'].any? { |pat| /^(\.\/)?#{pat}.*/ =~ path }
|
43
|
+
end
|
44
|
+
|
45
|
+
def tagf
|
46
|
+
@config['tagf']
|
47
|
+
end
|
48
|
+
|
49
|
+
def respect_git?
|
50
|
+
@config['git']
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_s
|
54
|
+
@config.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def ensure_ext_cmds(ext_cmds)
|
60
|
+
set_option('ext_cmds', ext_cmds, {})
|
61
|
+
end
|
62
|
+
|
63
|
+
def ensure_default_cmd(default_cmd)
|
64
|
+
set_option('default_cmd', default_cmd, 'ctags')
|
65
|
+
end
|
66
|
+
|
67
|
+
def ensure_excluded_exts(excluded_exts)
|
68
|
+
set_option('excluded_exts', excluded_exts, [])
|
69
|
+
end
|
70
|
+
|
71
|
+
def ensure_excluded_paths(excluded_paths)
|
72
|
+
set_option('excluded_paths', excluded_paths, [])
|
73
|
+
end
|
74
|
+
|
75
|
+
def ensure_tagf(tagf)
|
76
|
+
set_option('tagf', tagf, 'tags')
|
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
|
80
|
+
end
|
81
|
+
|
82
|
+
def ensure_git(git)
|
83
|
+
set_option('git', git, true)
|
84
|
+
if @config['git'] && !Helper.is_executable?('git')
|
85
|
+
raise ErrorGitNotExecutable, "'git' must be executable to use the --git option."
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def set_option(key, local_val, default)
|
90
|
+
unless local_val.nil?
|
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
|
95
|
+
end
|
96
|
+
|
97
|
+
def config_file_name(fname)
|
98
|
+
return fname unless fname.nil?
|
99
|
+
return global_config_file_name if File.file?(global_config_file_name)
|
100
|
+
nil
|
101
|
+
end
|
102
|
+
|
103
|
+
def global_config_file_name
|
104
|
+
"#{global_config_dir_name}/config.yml"
|
105
|
+
end
|
4
106
|
|
107
|
+
def global_config_dir_name
|
108
|
+
"#{ENV["HOME"]}/.config/tagrity"
|
5
109
|
end
|
6
110
|
end
|
7
111
|
end
|
@@ -1,9 +1,14 @@
|
|
1
1
|
require 'tagrity/tag_generator'
|
2
|
+
require 'tagrity/config_file'
|
2
3
|
|
3
4
|
module Tagrity
|
4
5
|
class FileCallbacks
|
5
|
-
def initialize
|
6
|
-
@tag_generator =
|
6
|
+
def initialize(tag_generator)
|
7
|
+
@tag_generator = tag_generator
|
8
|
+
end
|
9
|
+
|
10
|
+
def on_fresh
|
11
|
+
@tag_generator.generate_all
|
7
12
|
end
|
8
13
|
|
9
14
|
def on_files_modified(files)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Tagrity
|
2
|
+
class Helper
|
3
|
+
root = ENV['TEST'] ? __dir__ : "#{ENV['HOME']}/.tagrity/"
|
4
|
+
RUN_DIR = File.join(root, 'var/run').freeze
|
5
|
+
LOG_DIR = File.join(root, 'var/log').freeze
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def run_dir
|
9
|
+
ensure_data_dirs
|
10
|
+
RUN_DIR
|
11
|
+
end
|
12
|
+
|
13
|
+
def is_executable?(cmd)
|
14
|
+
!%x{command -v #{cmd}}.empty?
|
15
|
+
end
|
16
|
+
|
17
|
+
def kill(pid)
|
18
|
+
Process.kill('HUP', pid)
|
19
|
+
end
|
20
|
+
|
21
|
+
def alive?(pid)
|
22
|
+
Process.kill(0, pid) # signal 0 checks if pid is alive
|
23
|
+
true
|
24
|
+
rescue Errno::ESRCH
|
25
|
+
false
|
26
|
+
rescue Errno::EPERM
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def is_git_dir?
|
31
|
+
return @is_git_dir unless @is_git_dir.nil?
|
32
|
+
`git rev-parse --git-dir &> /dev/null`
|
33
|
+
if $?.exitstatus == 0
|
34
|
+
@is_git_dir = true
|
35
|
+
else
|
36
|
+
@is_git_dir = false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_file_ignored?(file)
|
41
|
+
`git check-ignore -q #{file} &> /dev/null`
|
42
|
+
$?.exitstatus == 0
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_file_tracked?(file)
|
46
|
+
`git ls-files --error-unmatch #{file} &> /dev/null`
|
47
|
+
$?.exitstatus == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def ensure_data_dirs
|
53
|
+
FileUtils.mkdir_p(RUN_DIR)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/tagrity/pid_file.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
+
require 'tagrity/helper'
|
2
|
+
|
1
3
|
module Tagrity
|
2
4
|
class PidFile
|
3
|
-
RUN_DIR = "#{__dir__}/../../var/run"
|
4
|
-
|
5
5
|
class << self
|
6
6
|
def write(pid_file)
|
7
|
-
File.write("#{run_dir}/#{pid_file.name}", pid_file.dir)
|
7
|
+
File.write("#{Helper.run_dir}/#{pid_file.name}", pid_file.dir)
|
8
8
|
end
|
9
9
|
|
10
10
|
def delete(dir)
|
11
|
-
pid_file_paths = Dir.glob("#{run_dir}/#{dir.split('/').last}.*.pid").select do |path|
|
11
|
+
pid_file_paths = Dir.glob("#{Helper.run_dir}/#{dir.split('/').last}.*.pid").select do |path|
|
12
12
|
full_dir = File.read(path)
|
13
13
|
File.realdirpath(full_dir) == File.realdirpath(dir)
|
14
14
|
end
|
15
15
|
|
16
16
|
pid_file_paths.each do |path|
|
17
17
|
File.delete(path)
|
18
|
-
|
18
|
+
Helper.kill(pid_from_path(path))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def alive_pid_files(dir: nil)
|
23
|
-
Dir.glob("#{run_dir}/*").reduce([]) do |pid_files, path|
|
23
|
+
Dir.glob("#{Helper.run_dir}/*").reduce([]) do |pid_files, path|
|
24
24
|
pid = pid_from_path(path)
|
25
25
|
pid_file_dir = File.read(path)
|
26
26
|
|
27
27
|
if dir.nil? || is_same_dirs(pid_file_dir, dir)
|
28
|
-
if
|
28
|
+
if Helper.alive?(pid)
|
29
29
|
pid_files << PidFile.new(pid_file_dir, pid)
|
30
30
|
else
|
31
31
|
File.delete(path)
|
@@ -36,23 +36,12 @@ module Tagrity
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def run_dir
|
40
|
-
ensure_dirs
|
41
|
-
RUN_DIR
|
42
|
-
end
|
43
|
-
|
44
39
|
private
|
45
40
|
|
46
41
|
def is_same_dirs(dir1, dir2)
|
47
42
|
File.realdirpath(dir1) == File.realdirpath(dir2)
|
48
43
|
end
|
49
44
|
|
50
|
-
def ensure_dirs
|
51
|
-
return if @ensure_dirs_done
|
52
|
-
FileUtils.mkdir_p(RUN_DIR)
|
53
|
-
@ensure_dirs_done = true
|
54
|
-
end
|
55
|
-
|
56
45
|
def pid_from_path(pid_file_name)
|
57
46
|
pid_file_name.split('.')[-2].to_i
|
58
47
|
end
|
@@ -76,13 +65,13 @@ module Tagrity
|
|
76
65
|
|
77
66
|
def delete
|
78
67
|
File.delete(pid_file_path)
|
79
|
-
|
68
|
+
Helper.kill(pid.to_i)
|
80
69
|
end
|
81
70
|
|
82
71
|
private
|
83
72
|
|
84
73
|
def pid_file_path
|
85
|
-
"#{
|
74
|
+
"#{Helper.run_dir}/#{name}"
|
86
75
|
end
|
87
76
|
end
|
88
77
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'tagrity/file_callbacks'
|
2
|
+
require 'tagrity/config_file'
|
3
|
+
require 'tagrity/tag_generator'
|
4
|
+
|
5
|
+
module Tagrity
|
6
|
+
class Provider
|
7
|
+
class << self
|
8
|
+
def provide(want)
|
9
|
+
case want
|
10
|
+
when :file_callbacks
|
11
|
+
provide_file_callbacks
|
12
|
+
when :tag_generator
|
13
|
+
provide_tag_generator
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def provide_file_callbacks
|
18
|
+
FileCallbacks.new(provide(:tag_generator))
|
19
|
+
end
|
20
|
+
|
21
|
+
def provide_tag_generator
|
22
|
+
TagGenerator.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,33 +1,106 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'pry'
|
5
|
+
require 'tagrity/helper'
|
6
|
+
|
1
7
|
module Tagrity
|
2
8
|
class TagGenerator
|
3
9
|
class ExecutableNonExist < StandardError; end
|
4
10
|
|
5
11
|
def initialize
|
6
12
|
assert_executables
|
13
|
+
@config = ConfigFile.instance
|
7
14
|
end
|
8
15
|
|
9
16
|
def generate_all
|
17
|
+
if File.exists?(tagf)
|
18
|
+
File.delete(tagf)
|
19
|
+
end
|
20
|
+
if check_git?
|
21
|
+
files = `git ls-files 2> /dev/null`.split
|
22
|
+
else
|
23
|
+
files = `find * 2> /dev/null`.split
|
24
|
+
end
|
25
|
+
if $?.exitstatus == 0
|
26
|
+
generate(files)
|
27
|
+
else
|
28
|
+
puts "Failed to get a listing of all files under pwd for use with --fresh."
|
29
|
+
end
|
10
30
|
end
|
11
31
|
|
12
32
|
def generate(files)
|
13
33
|
return if files.empty?
|
14
|
-
|
34
|
+
files
|
35
|
+
.select { |file| generate_tags?(file) }
|
36
|
+
.group_by { |file| @config.ft_to_cmd(file.partition('.').last) }
|
37
|
+
.each do |cmd, fnames|
|
38
|
+
Tempfile.create do |tmpf|
|
39
|
+
IO::write(tmpf.path, fnames.join("\n"))
|
40
|
+
system(cmd, '-f', tagf, '--append', '-L', tmpf.path, out: File::NULL)
|
41
|
+
if $?.exitstatus == 0
|
42
|
+
puts "{#{cmd}} generated tags for #{fnames} into #{tagf}"
|
43
|
+
else
|
44
|
+
puts "{#{cmd}} failed to generate tags for #{fnames} into #{tagf}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
15
48
|
end
|
16
49
|
|
17
50
|
def delete_files_tags(files)
|
18
51
|
return if files.empty?
|
19
|
-
|
20
|
-
|
52
|
+
Tempfile.create do |tmpf|
|
53
|
+
File.open(tagf) do |f|
|
54
|
+
f.each_line do |line|
|
55
|
+
unless files.any? { |fname| line.include?("\t#{fname}\t") }
|
56
|
+
tmpf.write line
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
tmpf.rewind
|
61
|
+
FileUtils.mv(tmpf.path, tagf, force: true)
|
62
|
+
puts "Deleted tags for #{files} from #{tagf}"
|
63
|
+
end
|
21
64
|
end
|
22
65
|
|
23
66
|
private
|
24
67
|
|
68
|
+
def generate_tags?(file)
|
69
|
+
copacetic_with_git?(file) && indexable?(file)
|
70
|
+
end
|
71
|
+
|
72
|
+
def indexable?(file)
|
73
|
+
file != tagf && !is_file_excluded(file) && File.readable?(file)
|
74
|
+
end
|
75
|
+
|
76
|
+
def copacetic_with_git?(file)
|
77
|
+
!(check_git? && !Helper.is_file_tracked?(file))
|
78
|
+
end
|
79
|
+
|
80
|
+
def check_git?
|
81
|
+
@config.respect_git? && Helper.is_git_dir?
|
82
|
+
end
|
83
|
+
|
84
|
+
def is_file_excluded(fname)
|
85
|
+
@config.is_ft_excluded(fname.partition('.').last) || @config.is_path_excluded(fname)
|
86
|
+
end
|
87
|
+
|
25
88
|
def assert_executables
|
26
89
|
%w(cat grep mv).each do |exe|
|
27
|
-
if
|
90
|
+
if !Helper.is_executable?(exe)
|
28
91
|
raise ExecutableNonExist, "tagrity depends on the executable #{exe}"
|
29
92
|
end
|
30
93
|
end
|
31
94
|
end
|
95
|
+
|
96
|
+
def tagf
|
97
|
+
@config.tagf
|
98
|
+
end
|
99
|
+
|
100
|
+
def tmp_file
|
101
|
+
tmpdir = "#{Dir.tmpdir}/tagrity"
|
102
|
+
FileUtils.mkdir_p(tmpdir)
|
103
|
+
"#{tmpdir}/#{Process.pid}.tmptags"
|
104
|
+
end
|
32
105
|
end
|
33
106
|
end
|
data/lib/tagrity/version.rb
CHANGED
data/sample_config.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# ext_cmds allows different tag generators to be used depending on the file extension.
|
2
|
+
# Multiple extensions does not work, *.html.erb files will be picked up as erb.
|
3
|
+
# ext_cmds:
|
4
|
+
# <file extension>: <command to use to generate tags for this file extension>
|
5
|
+
# DEFAULT: empty
|
6
|
+
ext_cmds:
|
7
|
+
rb: ripper-tags
|
8
|
+
c: ctags
|
9
|
+
go: gotags
|
10
|
+
|
11
|
+
# default_cmd specifies the default command to be used to generate tags
|
12
|
+
# default_cmd: <command>
|
13
|
+
# DEFAULT: ctags
|
14
|
+
default_cmd: ctags
|
15
|
+
|
16
|
+
# tagf is the filename (relative) to generate tags into
|
17
|
+
# tagf: <filename>
|
18
|
+
# DEFAULT: tags
|
19
|
+
tagf: tags
|
20
|
+
|
21
|
+
# excluded_exts specifies which file extensions to not generate tags for.
|
22
|
+
# excluded_exts: [<file extension>, ...]
|
23
|
+
# DEFAULT: []
|
24
|
+
excluded_exts: [rb, h, js]
|
25
|
+
|
26
|
+
# excluded_paths specifies which paths to ignore.
|
27
|
+
# It's usually better to avoid this since by default tagrity will only look
|
28
|
+
# at files which are tracked by git.
|
29
|
+
# excluded_paths: [<path>, ...]
|
30
|
+
# DEFAULT: []
|
31
|
+
excluded_paths: [vendor, node_modules]
|
data/tagrity.gemspec
CHANGED
@@ -32,4 +32,6 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency "bundler", "~> 2.0"
|
33
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
34
34
|
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_development_dependency "ripper-tags", "~> 0.8.0"
|
36
|
+
spec.add_dependency "pry", "~> 0.9.9"
|
35
37
|
end
|
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.6
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ripper-tags
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.8.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.8.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.9.9
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.9.9
|
83
111
|
description: Ditto
|
84
112
|
email:
|
85
113
|
- rethy.spud@gmail.com
|
@@ -88,6 +116,7 @@ executables:
|
|
88
116
|
extensions: []
|
89
117
|
extra_rdoc_files: []
|
90
118
|
files:
|
119
|
+
- ".byebug_history"
|
91
120
|
- ".gitignore"
|
92
121
|
- ".rspec"
|
93
122
|
- ".travis.yml"
|
@@ -102,16 +131,17 @@ files:
|
|
102
131
|
- exe/tagrity
|
103
132
|
- lib/tagrity.rb
|
104
133
|
- lib/tagrity/cli.rb
|
105
|
-
- lib/tagrity/commands/restart.rb
|
106
134
|
- lib/tagrity/commands/start.rb
|
107
135
|
- lib/tagrity/commands/status.rb
|
108
136
|
- lib/tagrity/commands/stop.rb
|
109
137
|
- lib/tagrity/config_file.rb
|
110
138
|
- lib/tagrity/file_callbacks.rb
|
139
|
+
- lib/tagrity/helper.rb
|
111
140
|
- lib/tagrity/pid_file.rb
|
112
|
-
- lib/tagrity/
|
141
|
+
- lib/tagrity/provider.rb
|
113
142
|
- lib/tagrity/tag_generator.rb
|
114
143
|
- lib/tagrity/version.rb
|
144
|
+
- sample_config.yml
|
115
145
|
- tagrity.gemspec
|
116
146
|
homepage: https://github.com/RRethy/tagrity
|
117
147
|
licenses:
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Tagrity
|
2
|
-
class ProcessHelper
|
3
|
-
class << self
|
4
|
-
def kill(pid)
|
5
|
-
Process.kill('HUP', pid)
|
6
|
-
end
|
7
|
-
|
8
|
-
def alive?(pid)
|
9
|
-
Process.kill(0, pid) # signal 0 checks if pid is alive
|
10
|
-
true
|
11
|
-
rescue Errno::ESRCH
|
12
|
-
false
|
13
|
-
rescue Errno::EPERM
|
14
|
-
true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|