vimpk 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d6e8ca14353f2e289dcf72b6049f1f694b7277ca702c48e95526a3bbc736a7a
4
- data.tar.gz: efddf087e1596aa801a174dd30242bcf72913aeac50ba443976f7f0c5b64111a
3
+ metadata.gz: c1ddacdbd87289382f61dff2859903c4091456cd64ace528029ad8e497d12b0e
4
+ data.tar.gz: 72186f79e1e2fd67ff630d658fc6540410954cd18924d2756fec039b8adbedfa
5
5
  SHA512:
6
- metadata.gz: 78c8fbb9298b12bce49f149507c7b89b7f2437b2942f53320f42e0c79fc63843ef83e565f0cbfc716657669f19c04b2150715aa8e8a60ed959cbca410065f7df
7
- data.tar.gz: 575726746604f123e148bee44fc9c001222df4d7dfa9bf7cb092021a08e34aadd522c23d2b949ba383c9d86dbd5cfd2c4e1891ee775ac27d0e3b6797d23d4cc5
6
+ metadata.gz: b89b712ec4278d72e87f10c62040251eeae5a3c8f3cd438a97b2507cb3083eb05e794935b311f08fedc453ab23d67557483e72e747d4336eb01a1ba942ca816e
7
+ data.tar.gz: 5b85de54d8df5318fb988e981dca5e1f502578eb9cdb1b5de505c453e9357b4ff131ad65ea4b384684f940d1526d96d71392390b8480895edaf2d2173bdeaf22
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 Install::PackageExistsError => e
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 Move::PackageNotFoundError, Move::MultiplePackagesFoundError, ArgumentError => e
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,22 @@ module VimPK
121
121
  puts
122
122
  puts "Displaying diffs…"
123
123
 
124
- statuses.each do |basename, status|
125
- puts status.lines.map { |line| "#{basename}: #{colorize_diff line}" }.join
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
126
130
  end
127
131
  end
128
132
  end
129
133
  end
130
134
 
131
135
  def remove_command(name = nil)
132
- Remove.new(name, @options).call
136
+ Commands::Remove.new(name, @options).call
133
137
 
134
138
  puts colorize("Package #{name} removed.", color: :green)
135
- rescue ArgumentError, VimPK::Remove::PackageNotFoundError => e
139
+ rescue ArgumentError, PackageNotFoundError => e
136
140
  abort colorize(e.message, color: :red)
137
141
  end
138
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
@@ -0,0 +1,9 @@
1
+ module VimPK
2
+ module Commands
3
+ autoload :Install, "vimpk/commands/install"
4
+ autoload :List, "vimpk/commands/list"
5
+ autoload :Move, "vimpk/commands/move"
6
+ autoload :Remove, "vimpk/commands/remove"
7
+ autoload :Update, "vimpk/commands/update"
8
+ end
9
+ end
@@ -1,6 +1,7 @@
1
1
  module VimPK
2
2
  class ThreadPool
3
3
  def initialize(size = Etc.nprocessors * 2)
4
+ Thread.abort_on_exception = true
4
5
  @size = size
5
6
  @jobs = Queue.new
6
7
  @workers = Array.new(size) do
data/lib/vimpk/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VimPK
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
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
- class Error < StandardError; end
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.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-17 00:00:00.000000000 Z
11
+ date: 2024-03-22 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