vimpk 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vimpk/cli.rb +16 -10
- 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/thread_pool.rb +1 -0
- data/lib/vimpk/version.rb +1 -1
- data/lib/vimpk.rb +5 -8
- metadata +8 -7
- data/lib/vimpk/install.rb +0 -25
- data/lib/vimpk/list.rb +0 -24
- 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: 01fb520c5ac8442484ced90c25edf4fe7893102dff9f95d0be631ba49126bda7
|
4
|
+
data.tar.gz: 7b73fb419b7ca3a76c7a4bfcbe09864e86520786c4642a47c90bf9a75a066631
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e17f43b36f9faa022530e58097e06a247182aa44be8bc00e2f15162f016e4a2c16d4d6ebb64d6f237b28c31148e5338b8ef2afe033fc98410413b6f2b255ba32
|
7
|
+
data.tar.gz: 6d1ab5c8ccaaac98908c69c1f1baee4e032b93dec5a9fb759ce65d08a11991732a8fbfc05963fe21b76f0063cbf1acb2a48a931e91953df272629d0c9eb2596c
|
data/lib/vimpk/cli.rb
CHANGED
@@ -53,36 +53,36 @@ module VimPK
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def list_command
|
56
|
-
command = List.new(@options)
|
56
|
+
command = Commands::List.new(@options)
|
57
57
|
list = command.call
|
58
58
|
puts list.sort_by(&:downcase)
|
59
59
|
end
|
60
60
|
|
61
61
|
def install_command(package = nil)
|
62
62
|
time = Time.now
|
63
|
-
command = Install.new(package, @options)
|
63
|
+
command = Commands::Install.new(package, @options)
|
64
64
|
puts "Installing #{package} to #{command.dest}…"
|
65
65
|
command.call
|
66
66
|
puts colorize("Installed #{package} to #{command.dest}. Took #{Time.now - time} seconds.", color: :green)
|
67
67
|
rescue Git::GitError => e
|
68
68
|
warn colorize("Error: #{e.message}", color: :yellow)
|
69
69
|
abort e.output.lines.map { |line| " #{line}" }.join
|
70
|
-
rescue
|
70
|
+
rescue PackageExistsError => e
|
71
71
|
abort colorize("Error: #{e.message}", color: :red)
|
72
72
|
rescue ArgumentError => e
|
73
73
|
abort colorize("Error: #{e.message}", color: :red)
|
74
74
|
end
|
75
75
|
|
76
76
|
def move_command(name = nil)
|
77
|
-
command = Move.new(name, @options)
|
77
|
+
command = Commands::Move.new(name, @options)
|
78
78
|
command.call
|
79
79
|
puts colorize("Moved #{name} to #{command.dest}.", color: :green)
|
80
|
-
rescue
|
80
|
+
rescue PackageNotFoundError, MultiplePackagesFoundError, ArgumentError => e
|
81
81
|
abort colorize(e.message, color: :red)
|
82
82
|
end
|
83
83
|
|
84
84
|
def update_command
|
85
|
-
command = Update.new(@options)
|
85
|
+
command = Commands::Update.new(@options)
|
86
86
|
puts "Updating #{command.plugins.size} packages in #{@options[:path]}…"
|
87
87
|
start_time = Time.now
|
88
88
|
command.call
|
@@ -121,18 +121,24 @@ module VimPK
|
|
121
121
|
puts
|
122
122
|
puts "Displaying diffs…"
|
123
123
|
|
124
|
-
|
125
|
-
|
124
|
+
options = ENV["NO_COLOR"] ? [] : %w[--use-color -R]
|
125
|
+
|
126
|
+
IO.popen(["less", *options], "w") do |io|
|
127
|
+
statuses.each do |basename, status|
|
128
|
+
status.lines.each do |line|
|
129
|
+
io.print "#{basename}: #{colorize_diff line}"
|
130
|
+
end
|
131
|
+
end
|
126
132
|
end
|
127
133
|
end
|
128
134
|
end
|
129
135
|
end
|
130
136
|
|
131
137
|
def remove_command(name = nil)
|
132
|
-
Remove.new(name, @options).call
|
138
|
+
Commands::Remove.new(name, @options).call
|
133
139
|
|
134
140
|
puts colorize("Package #{name} removed.", color: :green)
|
135
|
-
rescue ArgumentError,
|
141
|
+
rescue ArgumentError, PackageNotFoundError => e
|
136
142
|
abort colorize(e.message, color: :red)
|
137
143
|
end
|
138
144
|
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/thread_pool.rb
CHANGED
data/lib/vimpk/version.rb
CHANGED
data/lib/vimpk.rb
CHANGED
@@ -5,20 +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 :List, "vimpk/list"
|
19
|
-
autoload :Move, "vimpk/move"
|
20
19
|
autoload :Options, "vimpk/options"
|
21
|
-
autoload :Remove, "vimpk/remove"
|
22
20
|
autoload :ThreadPool, "vimpk/thread_pool"
|
23
|
-
autoload :Update, "vimpk/update"
|
24
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.6.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-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -24,15 +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/list.rb
|
31
|
-
- lib/vimpk/move.rb
|
32
35
|
- lib/vimpk/options.rb
|
33
|
-
- lib/vimpk/remove.rb
|
34
36
|
- lib/vimpk/thread_pool.rb
|
35
|
-
- lib/vimpk/update.rb
|
36
37
|
- lib/vimpk/version.rb
|
37
38
|
- vimpk.gemspec
|
38
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, options)
|
10
|
-
@package = package || raise(ArgumentError, "Package name is required")
|
11
|
-
@path = options.path
|
12
|
-
@pack = options.pack || options.default_pack
|
13
|
-
@type = options.type || options.default_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/list.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require "fileutils"
|
2
|
-
|
3
|
-
module VimPK
|
4
|
-
class List
|
5
|
-
PackageNotFoundError = Class.new(StandardError)
|
6
|
-
|
7
|
-
attr_reader :dest
|
8
|
-
|
9
|
-
def initialize(options)
|
10
|
-
@path = options.path
|
11
|
-
@pack = options.pack || "*"
|
12
|
-
@type = options.type || "{start,opt}"
|
13
|
-
end
|
14
|
-
|
15
|
-
def call
|
16
|
-
pattern = File.join(@path, @pack, @type, "*")
|
17
|
-
glob = Dir.glob(pattern)
|
18
|
-
|
19
|
-
raise PackageNotFoundError, "No packages were found in #{pattern}." if glob.empty?
|
20
|
-
|
21
|
-
glob
|
22
|
-
end
|
23
|
-
end
|
24
|
-
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, options)
|
11
|
-
@name = name || raise(ArgumentError, "Package name is required")
|
12
|
-
raise ArgumentError, "New pack or type is required" unless pack || type
|
13
|
-
@path = options.path
|
14
|
-
@pack = options.pack
|
15
|
-
@type = options.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, options)
|
8
|
-
@name = name || raise(ArgumentError, "Package name is required")
|
9
|
-
@path = options.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(options)
|
8
|
-
@pack_dir = File.expand_path(options.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
|