tagrity 0.1.1 → 0.1.2
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/Gemfile.lock +3 -1
- data/README.md +47 -4
- data/lib/tagrity/cli.rb +19 -11
- data/lib/tagrity/commands/start.rb +4 -6
- data/lib/tagrity/config_file.rb +90 -1
- data/lib/tagrity/executable_helper.rb +9 -0
- data/lib/tagrity/file_callbacks.rb +3 -2
- data/lib/tagrity/provider.rb +26 -0
- data/lib/tagrity/tag_generator.rb +26 -7
- data/lib/tagrity/version.rb +1 -1
- data/tagrity.gemspec +1 -0
- metadata +19 -4
- data/lib/tagrity/commands/restart.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38dc3f96b14b1ef629c339a71faf41d448b7ca5281dd9d4e69ea4a2dcf167662
|
4
|
+
data.tar.gz: 731c6fb5f54d8c9ca850f2ee6a38018f6a1765b1663334b52ba2ad0f9929c686
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e228435fd32b23cb6d36b184889a82a170abc8422870d4321d36d5e2a17e89a108804ca4f83613ae41ad2e71091dae20a3e59652af5d715fa1f761055f6e1f6b
|
7
|
+
data.tar.gz: db4f8487a44f71e366bfa83e6308ab712236ea038348a08ca6302904ab6d8cf1b09b61eb0dcc96aa233b8f964f07b41985af27043756d2001e3d697b19dfdbb6
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tagrity (0.1.
|
4
|
+
tagrity (0.1.2)
|
5
5
|
listen (~> 3.0)
|
6
6
|
thor (~> 0.20)
|
7
7
|
|
@@ -17,6 +17,7 @@ GEM
|
|
17
17
|
rb-fsevent (0.10.3)
|
18
18
|
rb-inotify (0.10.0)
|
19
19
|
ffi (~> 1.0)
|
20
|
+
ripper-tags (0.8.0)
|
20
21
|
rspec (3.9.0)
|
21
22
|
rspec-core (~> 3.9.0)
|
22
23
|
rspec-expectations (~> 3.9.0)
|
@@ -38,6 +39,7 @@ PLATFORMS
|
|
38
39
|
DEPENDENCIES
|
39
40
|
bundler (~> 2.0)
|
40
41
|
rake (~> 10.0)
|
42
|
+
ripper-tags (~> 0.8.0)
|
41
43
|
rspec (~> 3.0)
|
42
44
|
tagrity!
|
43
45
|
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
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
|
|
@@ -22,7 +20,52 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
```
|
24
|
+
Commands:
|
25
|
+
tagrity help [COMMAND] # Describe available commands or one specific command
|
26
|
+
tagrity start # Start watching a directory (default to pwd)
|
27
|
+
tagrity status # List running tagrity processes and the directories being watched
|
28
|
+
tagrity stop # Stop watching a directory (default to pwd)
|
29
|
+
```
|
30
|
+
|
31
|
+
### start
|
32
|
+
|
33
|
+
```
|
34
|
+
Usage:
|
35
|
+
tagrity start
|
36
|
+
|
37
|
+
Options:
|
38
|
+
[--dir=DIR]
|
39
|
+
[--fg], [--no-fg]
|
40
|
+
[--configfile=CONFIGFILE]
|
41
|
+
[--tagf=TAGF]
|
42
|
+
[--default-cmd=DEFAULT_CMD]
|
43
|
+
[--excluded-exts=one two three]
|
44
|
+
[--excluded-paths=one two three]
|
45
|
+
|
46
|
+
Start watching a directory (default to pwd)
|
47
|
+
```
|
48
|
+
|
49
|
+
### stop
|
50
|
+
|
51
|
+
```
|
52
|
+
Usage:
|
53
|
+
tagrity stop
|
54
|
+
|
55
|
+
Options:
|
56
|
+
[--dir=DIR]
|
57
|
+
|
58
|
+
Stop watching a directory (default to pwd)
|
59
|
+
```
|
60
|
+
|
61
|
+
### status
|
62
|
+
|
63
|
+
```
|
64
|
+
Usage:
|
65
|
+
tagrity status
|
66
|
+
|
67
|
+
List running tagrity processes and the directories being watched
|
68
|
+
```
|
26
69
|
|
27
70
|
## Development
|
28
71
|
|
data/lib/tagrity/cli.rb
CHANGED
@@ -1,32 +1,30 @@
|
|
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
|
8
|
+
desc "start", "Start watching a directory (default to pwd)"
|
10
9
|
option :dir
|
11
10
|
option :fg, type: :boolean
|
11
|
+
option :configfile
|
12
|
+
option :tagf
|
13
|
+
option :default_cmd
|
14
|
+
option :excluded_exts, type: :array
|
15
|
+
option :excluded_paths, type: :array
|
12
16
|
def start()
|
17
|
+
setup_config
|
13
18
|
Command::Start::call(dir, fg?)
|
14
19
|
end
|
15
20
|
|
16
|
-
desc "stop", "Stop watching
|
21
|
+
desc "stop", "Stop watching a directory (default to pwd)"
|
17
22
|
option :dir
|
18
23
|
def stop()
|
19
24
|
Command::Stop::call(dir)
|
20
25
|
end
|
21
26
|
|
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"
|
27
|
+
desc "status", "List running tagrity processes and the directories being watched"
|
30
28
|
def status
|
31
29
|
Command::Status::call
|
32
30
|
end
|
@@ -42,5 +40,15 @@ module Tagrity
|
|
42
40
|
def fg?
|
43
41
|
options[:fg]
|
44
42
|
end
|
43
|
+
|
44
|
+
def setup_config
|
45
|
+
ConfigFile.instance.init(
|
46
|
+
configfile: options[:configfile],
|
47
|
+
default_cmd: options[:default_cmd],
|
48
|
+
tagf: options[:tagf],
|
49
|
+
excluded_exts: options[:excluded_exts],
|
50
|
+
excluded_paths: options[:excluded_paths]
|
51
|
+
)
|
52
|
+
end
|
45
53
|
end
|
46
54
|
end
|
@@ -2,6 +2,7 @@ require 'listen'
|
|
2
2
|
require 'tagrity/pid_file'
|
3
3
|
require 'tagrity/process_helper'
|
4
4
|
require 'tagrity/file_callbacks'
|
5
|
+
require 'tagrity/provider'
|
5
6
|
|
6
7
|
module Tagrity
|
7
8
|
module Command
|
@@ -12,22 +13,19 @@ module Tagrity
|
|
12
13
|
def call(dir, fg)
|
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
|
|
20
21
|
listener = Listen.to(
|
21
22
|
dir,
|
22
|
-
ignore: [
|
23
|
+
ignore: [/^\.?tags$/],
|
23
24
|
relative: true,
|
24
25
|
) do |modified, added, removed|
|
25
26
|
callbacks.on_files_modified(modified)
|
26
27
|
callbacks.on_files_added(added)
|
27
28
|
callbacks.on_files_removed(removed)
|
28
|
-
puts "modified absolute paths: #{modified}"
|
29
|
-
puts "added absolute paths: #{added}"
|
30
|
-
puts "removed absolute paths: #{removed}"
|
31
29
|
end
|
32
30
|
listener.start
|
33
31
|
sleep
|
data/lib/tagrity/config_file.rb
CHANGED
@@ -1,7 +1,96 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'singleton'
|
3
|
+
require 'tagrity/executable_helper'
|
4
|
+
|
1
5
|
module Tagrity
|
2
6
|
class ConfigFile
|
3
|
-
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
class ErrorTagFileNotWritable < StandardError; end
|
10
|
+
|
11
|
+
def init(
|
12
|
+
configfile:,
|
13
|
+
default_cmd:,
|
14
|
+
tagf:,
|
15
|
+
excluded_exts:,
|
16
|
+
excluded_paths:
|
17
|
+
)
|
18
|
+
fname = config_file_name(configfile)
|
19
|
+
@config = if fname.nil? then {} else YAML.load_file(fname) end
|
20
|
+
ensure_ext_cmds
|
21
|
+
ensure_default_cmd(default_cmd)
|
22
|
+
ensure_tagf(tagf)
|
23
|
+
ensure_excluded_exts(excluded_exts)
|
24
|
+
ensure_excluded_paths(excluded_paths)
|
25
|
+
end
|
26
|
+
|
27
|
+
def ft_to_cmd(ext)
|
28
|
+
ft_cmd = @config['ext_cmds'][ext]
|
29
|
+
return @config['default_cmd'] if ft_cmd.nil? || !ExecutableHelper.is_executable(ft_cmd)
|
30
|
+
ft_cmd
|
31
|
+
end
|
32
|
+
|
33
|
+
def is_ft_excluded(ext)
|
34
|
+
@config['excluded_exts'].include?(ext)
|
35
|
+
end
|
36
|
+
|
37
|
+
def is_path_excluded(path)
|
38
|
+
@config['excluded_paths'].any? { |pat| /^(\.\/)?#{pat}.*/ =~ path }
|
39
|
+
end
|
40
|
+
|
41
|
+
def tagf
|
42
|
+
@config['tagf']
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
@config.to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def ensure_ext_cmds
|
52
|
+
set_option('ext_cmds', nil, {})
|
53
|
+
end
|
54
|
+
|
55
|
+
def ensure_default_cmd(default_cmd)
|
56
|
+
set_option('default_cmd', default_cmd, 'ctags')
|
57
|
+
end
|
58
|
+
|
59
|
+
def ensure_excluded_exts(excluded_exts)
|
60
|
+
set_option('excluded_exts', excluded_exts, [])
|
61
|
+
end
|
62
|
+
|
63
|
+
def ensure_excluded_paths(excluded_paths)
|
64
|
+
set_option('excluded_paths', excluded_paths, [])
|
65
|
+
end
|
66
|
+
|
67
|
+
def ensure_tagf(tagf)
|
68
|
+
set_option('tagf', tagf, 'tags')
|
69
|
+
unless File.writable?(@config['tagf'])
|
70
|
+
raise ErrorTagFileNotWritable, "#{@config['tagf']} must be writable to be used as the tag file."
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_option(key, local_val, default)
|
75
|
+
unless local_val.nil?
|
76
|
+
@config[key] = local_val
|
77
|
+
end
|
78
|
+
return if @config.key?(key) && !@config[key].nil? && @config[key].is_a?(default.class)
|
79
|
+
@config[key] = default
|
80
|
+
end
|
81
|
+
|
82
|
+
def config_file_name(fname)
|
83
|
+
return fname unless fname.nil?
|
84
|
+
return global_config_file_name if File.file?(global_config_file_name)
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
|
88
|
+
def global_config_file_name
|
89
|
+
"#{global_config_dir_name}/config.yml"
|
90
|
+
end
|
4
91
|
|
92
|
+
def global_config_dir_name
|
93
|
+
"#{ENV["HOME"]}/.config/tagrity"
|
5
94
|
end
|
6
95
|
end
|
7
96
|
end
|
@@ -1,9 +1,10 @@
|
|
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
|
7
8
|
end
|
8
9
|
|
9
10
|
def on_files_modified(files)
|
@@ -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,52 @@
|
|
1
|
+
require 'tagrity/executable_helper'
|
2
|
+
|
1
3
|
module Tagrity
|
2
4
|
class TagGenerator
|
3
5
|
class ExecutableNonExist < StandardError; end
|
4
6
|
|
5
7
|
def initialize
|
6
8
|
assert_executables
|
7
|
-
|
8
|
-
|
9
|
-
def generate_all
|
9
|
+
@config = ConfigFile.instance
|
10
10
|
end
|
11
11
|
|
12
12
|
def generate(files)
|
13
13
|
return if files.empty?
|
14
|
-
|
14
|
+
files
|
15
|
+
.select { |file| !dont_index_file(file) && File.readable?(file) }
|
16
|
+
.group_by { |file| @config.ft_to_cmd(file.partition('.').last) }
|
17
|
+
.each do |cmd, fnames|
|
18
|
+
`#{cmd} -f #{tagf} --append #{fnames.join(' ')}`
|
19
|
+
if $?.exitstatus != 0
|
20
|
+
puts "{#{cmd}} failed to generate tags for #{fnames} into #{tagf}"
|
21
|
+
else
|
22
|
+
puts "{#{cmd}} generated tags for #{fnames} into #{tagf}"
|
23
|
+
end
|
24
|
+
end
|
15
25
|
end
|
16
26
|
|
17
27
|
def delete_files_tags(files)
|
18
28
|
return if files.empty?
|
19
|
-
`cat
|
20
|
-
`mv .tags
|
29
|
+
`cat #{tagf} | grep -v -F #{files.map { |f| " -e \" #{f} \""}.join(' ')} > .tagrity.tags`
|
30
|
+
`mv -f .tagrity.tags #{tagf}`
|
31
|
+
puts "Deleted tags for #{files} from #{tagf}"
|
21
32
|
end
|
22
33
|
|
23
34
|
private
|
24
35
|
|
36
|
+
def dont_index_file(fname)
|
37
|
+
@config.is_ft_excluded(fname.partition('.').last) || @config.is_path_excluded(fname)
|
38
|
+
end
|
39
|
+
|
25
40
|
def assert_executables
|
26
41
|
%w(cat grep mv).each do |exe|
|
27
|
-
if
|
42
|
+
if !ExecutableHelper.is_executable(exe)
|
28
43
|
raise ExecutableNonExist, "tagrity depends on the executable #{exe}"
|
29
44
|
end
|
30
45
|
end
|
31
46
|
end
|
47
|
+
|
48
|
+
def tagf
|
49
|
+
@config.tagf
|
50
|
+
end
|
32
51
|
end
|
33
52
|
end
|
data/lib/tagrity/version.rb
CHANGED
data/tagrity.gemspec
CHANGED
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.2
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -80,6 +80,20 @@ 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
|
83
97
|
description: Ditto
|
84
98
|
email:
|
85
99
|
- rethy.spud@gmail.com
|
@@ -102,14 +116,15 @@ files:
|
|
102
116
|
- exe/tagrity
|
103
117
|
- lib/tagrity.rb
|
104
118
|
- lib/tagrity/cli.rb
|
105
|
-
- lib/tagrity/commands/restart.rb
|
106
119
|
- lib/tagrity/commands/start.rb
|
107
120
|
- lib/tagrity/commands/status.rb
|
108
121
|
- lib/tagrity/commands/stop.rb
|
109
122
|
- lib/tagrity/config_file.rb
|
123
|
+
- lib/tagrity/executable_helper.rb
|
110
124
|
- lib/tagrity/file_callbacks.rb
|
111
125
|
- lib/tagrity/pid_file.rb
|
112
126
|
- lib/tagrity/process_helper.rb
|
127
|
+
- lib/tagrity/provider.rb
|
113
128
|
- lib/tagrity/tag_generator.rb
|
114
129
|
- lib/tagrity/version.rb
|
115
130
|
- tagrity.gemspec
|
@@ -135,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
150
|
- !ruby/object:Gem::Version
|
136
151
|
version: '0'
|
137
152
|
requirements: []
|
138
|
-
rubygems_version: 3.0.
|
153
|
+
rubygems_version: 3.0.3
|
139
154
|
signing_key:
|
140
155
|
specification_version: 4
|
141
156
|
summary: Regenerate tags on file changes.
|