vimpk 0.3.0 → 0.5.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 +4 -4
- data/lib/vimpk/cli.rb +34 -21
- data/lib/vimpk/commands/install.rb +25 -0
- data/lib/vimpk/commands/list.rb +24 -0
- data/lib/vimpk/commands/move.rb +40 -0
- data/lib/vimpk/commands/remove.rb +24 -0
- data/lib/vimpk/commands/update.rb +26 -0
- data/lib/vimpk/commands.rb +9 -0
- data/lib/vimpk/options.rb +4 -3
- data/lib/vimpk/thread_pool.rb +1 -0
- data/lib/vimpk/version.rb +1 -1
- data/lib/vimpk.rb +5 -7
- metadata +8 -6
- data/lib/vimpk/install.rb +0 -25
- data/lib/vimpk/move.rb +0 -41
- data/lib/vimpk/remove.rb +0 -24
- data/lib/vimpk/update.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1ddacdbd87289382f61dff2859903c4091456cd64ace528029ad8e497d12b0e
|
4
|
+
data.tar.gz: 72186f79e1e2fd67ff630d658fc6540410954cd18924d2756fec039b8adbedfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b89b712ec4278d72e87f10c62040251eeae5a3c8f3cd438a97b2507cb3083eb05e794935b311f08fedc453ab23d67557483e72e747d4336eb01a1ba942ca816e
|
7
|
+
data.tar.gz: 5b85de54d8df5318fb988e981dca5e1f502578eb9cdb1b5de505c453e9357b4ff131ad65ea4b384684f940d1526d96d71392390b8480895edaf2d2173bdeaf22
|
data/lib/vimpk/cli.rb
CHANGED
@@ -19,6 +19,7 @@ module VimPK
|
|
19
19
|
def call
|
20
20
|
if @command
|
21
21
|
send(@command, *@argv)
|
22
|
+
exit 0
|
22
23
|
else
|
23
24
|
puts @parser.parser
|
24
25
|
end
|
@@ -37,6 +38,8 @@ module VimPK
|
|
37
38
|
case name
|
38
39
|
when "i", "install"
|
39
40
|
:install_command
|
41
|
+
when "l", "list"
|
42
|
+
:list_command
|
40
43
|
when "mv", "move"
|
41
44
|
:move_command
|
42
45
|
when "u", "update"
|
@@ -49,43 +52,49 @@ module VimPK
|
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
55
|
+
def list_command
|
56
|
+
command = Commands::List.new(@options)
|
57
|
+
list = command.call
|
58
|
+
puts list.sort_by(&:downcase)
|
59
|
+
end
|
60
|
+
|
52
61
|
def install_command(package = nil)
|
53
62
|
time = Time.now
|
54
|
-
|
55
|
-
puts "Installing #{package} to #{
|
56
|
-
|
57
|
-
puts colorize("Installed #{package} to #{
|
63
|
+
command = Commands::Install.new(package, @options)
|
64
|
+
puts "Installing #{package} to #{command.dest}…"
|
65
|
+
command.call
|
66
|
+
puts colorize("Installed #{package} to #{command.dest}. Took #{Time.now - time} seconds.", color: :green)
|
58
67
|
rescue Git::GitError => e
|
59
68
|
warn colorize("Error: #{e.message}", color: :yellow)
|
60
69
|
abort e.output.lines.map { |line| " #{line}" }.join
|
61
|
-
rescue
|
70
|
+
rescue PackageExistsError => e
|
62
71
|
abort colorize("Error: #{e.message}", color: :red)
|
63
72
|
rescue ArgumentError => e
|
64
73
|
abort colorize("Error: #{e.message}", color: :red)
|
65
74
|
end
|
66
75
|
|
67
76
|
def move_command(name = nil)
|
68
|
-
|
69
|
-
|
70
|
-
puts colorize("Moved #{name} to #{
|
71
|
-
rescue
|
77
|
+
command = Commands::Move.new(name, @options)
|
78
|
+
command.call
|
79
|
+
puts colorize("Moved #{name} to #{command.dest}.", color: :green)
|
80
|
+
rescue PackageNotFoundError, MultiplePackagesFoundError, ArgumentError => e
|
72
81
|
abort colorize(e.message, color: :red)
|
73
82
|
end
|
74
83
|
|
75
84
|
def update_command
|
76
|
-
|
77
|
-
puts "Updating #{
|
85
|
+
command = Commands::Update.new(@options)
|
86
|
+
puts "Updating #{command.plugins.size} packages in #{@options[:path]}…"
|
78
87
|
start_time = Time.now
|
79
|
-
|
88
|
+
command.call
|
80
89
|
|
81
90
|
statuses = {}
|
82
91
|
|
83
|
-
while (log =
|
92
|
+
while (log = command.logs.pop)
|
84
93
|
basename = log[:basename]
|
85
94
|
statuses[basename] = log[:log]
|
86
95
|
end
|
87
96
|
|
88
|
-
basenames =
|
97
|
+
basenames = command.plugins.map { |dir| File.basename(dir) }.sort_by(&:downcase)
|
89
98
|
|
90
99
|
max_name_length = statuses.keys.map(&:length).max
|
91
100
|
|
@@ -97,11 +106,11 @@ module VimPK
|
|
97
106
|
end
|
98
107
|
end
|
99
108
|
|
100
|
-
if statuses.size <
|
101
|
-
puts "The remaining #{
|
109
|
+
if statuses.size < command.jobs.size
|
110
|
+
puts "The remaining #{command.jobs.size - statuses.size} plugins are up to date."
|
102
111
|
end
|
103
112
|
|
104
|
-
puts colorize("Finished updating #{
|
113
|
+
puts colorize("Finished updating #{command.jobs.size} plugins. Took #{Time.now - start_time} seconds.")
|
105
114
|
|
106
115
|
if statuses.size.nonzero?
|
107
116
|
print "Display diffs? (Y/n) "
|
@@ -112,18 +121,22 @@ module VimPK
|
|
112
121
|
puts
|
113
122
|
puts "Displaying diffs…"
|
114
123
|
|
115
|
-
|
116
|
-
|
124
|
+
IO.popen("less", "w") do |io|
|
125
|
+
statuses.each do |basename, status|
|
126
|
+
status.lines.each do |line|
|
127
|
+
io.puts "#{basename}: #{colorize_diff line}"
|
128
|
+
end
|
129
|
+
end
|
117
130
|
end
|
118
131
|
end
|
119
132
|
end
|
120
133
|
end
|
121
134
|
|
122
135
|
def remove_command(name = nil)
|
123
|
-
Remove.new(name, @options
|
136
|
+
Commands::Remove.new(name, @options).call
|
124
137
|
|
125
138
|
puts colorize("Package #{name} removed.", color: :green)
|
126
|
-
rescue ArgumentError,
|
139
|
+
rescue ArgumentError, PackageNotFoundError => e
|
127
140
|
abort colorize(e.message, color: :red)
|
128
141
|
end
|
129
142
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module VimPK
|
2
|
+
module Commands
|
3
|
+
class Install
|
4
|
+
include VimPK::Colorizer
|
5
|
+
|
6
|
+
attr_reader :dest
|
7
|
+
|
8
|
+
def initialize(package, options)
|
9
|
+
@package = package || raise(ArgumentError, "Package name is required")
|
10
|
+
@path = options.path
|
11
|
+
@pack = options.pack || options.default_pack
|
12
|
+
@type = options.type || options.default_type
|
13
|
+
@dest = File.join(@path, @pack, @type, File.basename(@package))
|
14
|
+
@source = "https://github.com/#{package}.git"
|
15
|
+
@git = Git
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
raise PackageExistsError, "Package #{@package} already exists at #{@dest}" if File.exist?(@dest)
|
20
|
+
|
21
|
+
Git.clone(@source, @dest, dir: @path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module VimPK
|
4
|
+
module Commands
|
5
|
+
class List
|
6
|
+
attr_reader :dest
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@path = options.path
|
10
|
+
@pack = options.pack || "*"
|
11
|
+
@type = options.type || "{start,opt}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
pattern = File.join(@path, @pack, @type, "*")
|
16
|
+
glob = Dir.glob(pattern)
|
17
|
+
|
18
|
+
raise PackageNotFoundError, "No packages were found in #{pattern}." if glob.empty?
|
19
|
+
|
20
|
+
glob
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module VimPK
|
4
|
+
module Commands
|
5
|
+
class Move
|
6
|
+
attr_reader :dest
|
7
|
+
|
8
|
+
def initialize(name, options)
|
9
|
+
raise ArgumentError, "New pack or type is required" unless options.pack || options.type
|
10
|
+
@name = name || raise(ArgumentError, "Package name is required")
|
11
|
+
@path = options.path
|
12
|
+
@pack = options.pack
|
13
|
+
@type = options.type
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
glob = Dir.glob(File.join(@path, "*", "{start,opt}", @name))
|
18
|
+
|
19
|
+
if glob.empty?
|
20
|
+
raise PackageNotFoundError, "Package #{@name} not found in #{@path}."
|
21
|
+
elsif glob.size > 1
|
22
|
+
raise MultiplePackagesFoundError, "Multiple packages #{@name} found in #{glob.join(" and ")}."
|
23
|
+
else
|
24
|
+
source = glob.first
|
25
|
+
current_type = File.basename(File.dirname(source))
|
26
|
+
current_pack = File.basename(File.dirname(File.dirname(source)))
|
27
|
+
@dest = File.join(@path, @pack || current_pack, @type || current_type, @name)
|
28
|
+
|
29
|
+
if File.exist?(dest)
|
30
|
+
raise ArgumentError, "Package #{@name} already exists in #{dest}."
|
31
|
+
else
|
32
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
33
|
+
end
|
34
|
+
|
35
|
+
FileUtils.mv(source, dest)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module VimPK
|
4
|
+
module Commands
|
5
|
+
class Remove
|
6
|
+
def initialize(name, options)
|
7
|
+
@name = name || raise(ArgumentError, "Package name is required")
|
8
|
+
@path = options.path
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
glob = Dir.glob(File.join(@path, "*", "{start,opt}", @name))
|
13
|
+
|
14
|
+
if glob.empty?
|
15
|
+
raise PackageNotFoundError, "Package #{@name} not found in #{@path}."
|
16
|
+
else
|
17
|
+
glob.each do |dir|
|
18
|
+
FileUtils.rm_rf(dir)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module VimPK
|
2
|
+
module Commands
|
3
|
+
class Update
|
4
|
+
include VimPK::Colorizer
|
5
|
+
|
6
|
+
attr_reader :jobs, :logs, :plugins
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@pack_dir = File.expand_path(options.path)
|
10
|
+
@logs = Queue.new
|
11
|
+
@pool = ThreadPool.new
|
12
|
+
@plugins = Dir.glob(File.join(@pack_dir, "*", "{start,opt}", "*", ".git")).sort.map(&File.method(:dirname))
|
13
|
+
@jobs = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
@jobs = @plugins.map do |dir|
|
18
|
+
@pool.schedule Job.new(dir, @logs)
|
19
|
+
end
|
20
|
+
|
21
|
+
@pool.shutdown
|
22
|
+
@logs.close
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/vimpk/options.rb
CHANGED
@@ -10,11 +10,11 @@ module VimPK
|
|
10
10
|
DEFAULT_TYPE = "start"
|
11
11
|
DEFAULT_PACK = "plugins"
|
12
12
|
|
13
|
-
DefaultOptions = Struct.new(:path, :pack, :type)
|
13
|
+
DefaultOptions = Struct.new(:path, :pack, :type, :default_pack, :default_type)
|
14
14
|
|
15
15
|
def initialize(argv)
|
16
16
|
@argv = argv
|
17
|
-
@options = DefaultOptions.new(DEFAULT_PATH, DEFAULT_PACK, DEFAULT_TYPE)
|
17
|
+
@options = DefaultOptions.new(DEFAULT_PATH, nil, nil, DEFAULT_PACK, DEFAULT_TYPE)
|
18
18
|
|
19
19
|
@parser = OptionParser.new do |parser|
|
20
20
|
parser.banner = "Usage: #{parser.program_name} [options] [command [options]"
|
@@ -54,7 +54,8 @@ module VimPK
|
|
54
54
|
parser.separator ""
|
55
55
|
parser.separator "Commands:"
|
56
56
|
parser.separator " i|install REPO/NAME [--opt|--start] [--pack=PATH] [--path=PATH] Install a package"
|
57
|
-
parser.separator "
|
57
|
+
parser.separator " l|list [--opt|--start] [--pack=PATH] [--path=PATH] List packages"
|
58
|
+
parser.separator " mv|move NAME [--opt|--start] [--pack=PATH] Move a package"
|
58
59
|
parser.separator " u|update Update all packages"
|
59
60
|
parser.separator " rm|remove NAME Remove all occurrences of a package"
|
60
61
|
end
|
data/lib/vimpk/thread_pool.rb
CHANGED
data/lib/vimpk/version.rb
CHANGED
data/lib/vimpk.rb
CHANGED
@@ -5,19 +5,17 @@ require "etc"
|
|
5
5
|
|
6
6
|
require_relative "vimpk/version"
|
7
7
|
|
8
|
-
Thread.abort_on_exception = true
|
9
|
-
|
10
8
|
module VimPK
|
11
|
-
|
9
|
+
Error = Class.new(StandardError)
|
10
|
+
PackageExistsError = Class.new(Error)
|
11
|
+
PackageNotFoundError = Class.new(Error)
|
12
|
+
MultiplePackagesFoundError = Class.new(Error)
|
12
13
|
|
13
14
|
autoload :CLI, "vimpk/cli"
|
15
|
+
autoload :Commands, "vimpk/commands"
|
14
16
|
autoload :Colorizer, "vimpk/colorizer"
|
15
17
|
autoload :Git, "vimpk/git"
|
16
|
-
autoload :Install, "vimpk/install"
|
17
18
|
autoload :Job, "vimpk/job"
|
18
|
-
autoload :Move, "vimpk/move"
|
19
19
|
autoload :Options, "vimpk/options"
|
20
|
-
autoload :Remove, "vimpk/remove"
|
21
20
|
autoload :ThreadPool, "vimpk/thread_pool"
|
22
|
-
autoload :Update, "vimpk/update"
|
23
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vimpk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Usewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -24,14 +24,16 @@ files:
|
|
24
24
|
- lib/vimpk.rb
|
25
25
|
- lib/vimpk/cli.rb
|
26
26
|
- lib/vimpk/colorizer.rb
|
27
|
+
- lib/vimpk/commands.rb
|
28
|
+
- lib/vimpk/commands/install.rb
|
29
|
+
- lib/vimpk/commands/list.rb
|
30
|
+
- lib/vimpk/commands/move.rb
|
31
|
+
- lib/vimpk/commands/remove.rb
|
32
|
+
- lib/vimpk/commands/update.rb
|
27
33
|
- lib/vimpk/git.rb
|
28
|
-
- lib/vimpk/install.rb
|
29
34
|
- lib/vimpk/job.rb
|
30
|
-
- lib/vimpk/move.rb
|
31
35
|
- lib/vimpk/options.rb
|
32
|
-
- lib/vimpk/remove.rb
|
33
36
|
- lib/vimpk/thread_pool.rb
|
34
|
-
- lib/vimpk/update.rb
|
35
37
|
- lib/vimpk/version.rb
|
36
38
|
- vimpk.gemspec
|
37
39
|
homepage: https://github.com/pusewicz/vimpk
|
data/lib/vimpk/install.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module VimPK
|
2
|
-
class Install
|
3
|
-
include VimPK::Colorizer
|
4
|
-
|
5
|
-
PackageExistsError = Class.new(StandardError)
|
6
|
-
|
7
|
-
attr_reader :dest
|
8
|
-
|
9
|
-
def initialize(package, path, pack, type)
|
10
|
-
@package = package || raise(ArgumentError, "Package name is required")
|
11
|
-
@path = path
|
12
|
-
@pack = pack
|
13
|
-
@type = type
|
14
|
-
@dest = File.join(@path, @pack, @type, File.basename(@package))
|
15
|
-
@source = "https://github.com/#{package}.git"
|
16
|
-
@git = Git
|
17
|
-
end
|
18
|
-
|
19
|
-
def call
|
20
|
-
raise PackageExistsError, "Package #{@package} already exists at #{@dest}" if File.exist?(@dest)
|
21
|
-
|
22
|
-
Git.clone(@source, @dest, dir: @path)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/vimpk/move.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require "fileutils"
|
2
|
-
|
3
|
-
module VimPK
|
4
|
-
class Move
|
5
|
-
PackageNotFoundError = Class.new(StandardError)
|
6
|
-
MultiplePackagesFoundError = Class.new(StandardError)
|
7
|
-
|
8
|
-
attr_reader :dest
|
9
|
-
|
10
|
-
def initialize(name, path, pack = nil, type = nil)
|
11
|
-
@name = name || raise(ArgumentError, "Package name is required")
|
12
|
-
raise ArgumentError, "New pack or type is required" unless pack || type
|
13
|
-
@path = path
|
14
|
-
@pack = pack
|
15
|
-
@type = type
|
16
|
-
end
|
17
|
-
|
18
|
-
def call
|
19
|
-
glob = Dir.glob(File.join(@path, "*", "{start,opt}", @name))
|
20
|
-
|
21
|
-
if glob.empty?
|
22
|
-
raise PackageNotFoundError, "Package #{@name} not found in #{@path}."
|
23
|
-
elsif glob.size > 1
|
24
|
-
raise MultiplePackagesFoundError, "Multiple packages #{@name} found in #{glob.join(" and ")}."
|
25
|
-
else
|
26
|
-
source = glob.first
|
27
|
-
current_type = File.basename(File.dirname(source))
|
28
|
-
current_pack = File.basename(File.dirname(File.dirname(source)))
|
29
|
-
@dest = File.join(@path, @pack || current_pack, @type || current_type, @name)
|
30
|
-
|
31
|
-
if File.exist?(dest)
|
32
|
-
raise ArgumentError, "Package #{@name} already exists in #{dest}."
|
33
|
-
else
|
34
|
-
FileUtils.mkdir_p(File.dirname(dest))
|
35
|
-
end
|
36
|
-
|
37
|
-
FileUtils.mv(source, dest)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/lib/vimpk/remove.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require "fileutils"
|
2
|
-
|
3
|
-
module VimPK
|
4
|
-
class Remove
|
5
|
-
PackageNotFoundError = Class.new(StandardError)
|
6
|
-
|
7
|
-
def initialize(name, path)
|
8
|
-
@name = name || raise(ArgumentError, "Package name is required")
|
9
|
-
@path = path
|
10
|
-
end
|
11
|
-
|
12
|
-
def call
|
13
|
-
glob = Dir.glob(File.join(@path, "*", "{start,opt}", @name))
|
14
|
-
|
15
|
-
if glob.empty?
|
16
|
-
raise PackageNotFoundError, "Package #{@name} not found in #{@path}."
|
17
|
-
else
|
18
|
-
glob.each do |dir|
|
19
|
-
FileUtils.rm_rf(dir)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/vimpk/update.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module VimPK
|
2
|
-
class Update
|
3
|
-
include VimPK::Colorizer
|
4
|
-
|
5
|
-
attr_reader :jobs, :logs, :plugins
|
6
|
-
|
7
|
-
def initialize(path)
|
8
|
-
@pack_dir = File.expand_path(path)
|
9
|
-
@logs = Queue.new
|
10
|
-
@pool = ThreadPool.new
|
11
|
-
@plugins = Dir.glob(File.join(@pack_dir, "*", "{start,opt}", "*", ".git")).sort.map(&File.method(:dirname))
|
12
|
-
@jobs = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def call
|
16
|
-
@jobs = @plugins.map do |dir|
|
17
|
-
@pool.schedule Job.new(dir, @logs)
|
18
|
-
end
|
19
|
-
|
20
|
-
@pool.shutdown
|
21
|
-
@logs.close
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|