vimpk 0.1.1 → 0.2.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: b51ebecfb9301fe09e702bcb2dfed7efb76ecaf3f21480af3fd75cf6b16f34cf
4
- data.tar.gz: 2286aac5e850c870cad840020904a1aef54c320b30f861d647dc9b2dbeec0b26
3
+ metadata.gz: a4859149e17e0bc00e3a7230deeeecc6304eab4ed9acd2671509ea3d4ac016ae
4
+ data.tar.gz: ed44805797dbaa69cdf31c2767fdf928691169c9606df2ab610b412ea84adc20
5
5
  SHA512:
6
- metadata.gz: 7c4a3c50e3b85fa7b58ce0cda77de43925a64a1326a67a33f27f9e6fc0eb00954ac8d1b84decb2c31471232c7269d26bfdbb97f23ff25bf54e7b31b1b33b7f75
7
- data.tar.gz: d71de4cf60fdc354ae6613dfb5bd152becb4bcd50b72e72726afa15c6bb3febe3c2f6d39a2329cf5138a72dc5d6c5ee0dc2d1a9b61c11b2e73a87726b3c81555
6
+ metadata.gz: a7de3bfbf7b2fd882f2f9b8c0fc10b4cd8ad11bfff0b480a8b5fefc14bee11c10c393a521075bfe61de130ad3eb221fe573d2d11e1880121ce995b8374ed49c0
7
+ data.tar.gz: 3824e72fcc014941d33d1b139143185e752166a794809c7917c5824138db94c55b2caec2c896f88150c76c63d44f4d69c10ea66dbcd5c79fd151b3df5efeffe3
data/.overcommit.yml ADDED
@@ -0,0 +1,35 @@
1
+ ---
2
+ gemfile: Gemfile
3
+
4
+ PreCommit:
5
+ TrailingWhitespace:
6
+ enabled: true
7
+ YamlSyntax:
8
+ enabled: true
9
+
10
+ CommitMsg:
11
+ CapitalizedSubject:
12
+ enabled: false
13
+ EmptyMessage:
14
+ enabled: true
15
+ MessageFormat:
16
+ enabled: true
17
+ pattern: "^(feat|fix|docs|style|refactor|perf|test|chore|revert)?: [A-Z].*"
18
+ sample_message: "feat: Add new feature"
19
+ TrailingPeriod:
20
+ enabled: true
21
+ SpellCheck:
22
+ enabled: true
23
+
24
+ PostCheckout:
25
+ ALL:
26
+ quiet: true
27
+ BundleInstall:
28
+ enabled: true
29
+ quiet: true
30
+
31
+ PrePush:
32
+ ALL:
33
+ quiet: true
34
+ Minitest:
35
+ enabled: true
data/lib/vimpk/cli.rb CHANGED
@@ -4,33 +4,42 @@ module VimPK
4
4
  class CLI
5
5
  include Colorizer
6
6
 
7
- def initialize(args)
8
- @args = args
9
- @parser = VimPK::Options.new(args)
10
- @options = @parser.options
7
+ attr_reader :command
8
+
9
+ def initialize(argv)
10
+ @argv = argv
11
+ @parser = Options.new(argv)
12
+ @options = @parser.parse
11
13
  @command = determine_command
14
+ rescue OptionParser::MissingArgument, OptionParser::InvalidOption => e
15
+ warn e.message
16
+ abort "Use --help for usage information"
12
17
  end
13
18
 
14
19
  def call
15
20
  if @command
16
- send(@command, *@args)
21
+ send(@command, *@argv)
17
22
  else
18
23
  puts @parser.parser
19
24
  end
20
25
  end
21
26
 
22
27
  def determine_command
23
- return nil if @args.empty?
28
+ return nil if @argv.empty?
24
29
 
25
- case @args.shift&.downcase
30
+ name = @argv.shift&.downcase
31
+ case name
26
32
  when "i", "install"
27
33
  :install_command
34
+ when "mv", "move"
35
+ :move_command
28
36
  when "u", "update"
29
37
  :update_command
30
38
  when "rm", "remove"
31
39
  :remove_command
32
40
  else
33
- raise "Unknown command: #{name}"
41
+ warn colorize("Unknown command: #{name}", color: :red)
42
+ abort "Use --help for usage information"
34
43
  end
35
44
  end
36
45
 
@@ -41,12 +50,20 @@ module VimPK
41
50
  install.call
42
51
  puts colorize("Installed #{package} to #{install.dest}. Took #{Time.now - time} seconds.", color: :green)
43
52
  rescue Git::GitError => e
44
- puts colorize("Error: #{e.message}", color: :red)
53
+ warn colorize("Error: #{e.message}", color: :red)
45
54
  abort e.output.lines.map { |line| " #{line}" }.join
46
55
  rescue Install::PackageExistsError => e
47
- puts colorize("Error: #{e.message}", color: :red)
56
+ warn colorize("Error: #{e.message}", color: :red)
48
57
  rescue ArgumentError => e
49
- puts colorize("Error: #{e.message}", color: :red)
58
+ warn colorize("Error: #{e.message}", color: :red)
59
+ end
60
+
61
+ def move_command(name = nil)
62
+ move = Move.new(name, @options[:path], @options[:pack], @options[:type])
63
+ move.call
64
+ puts colorize("Moved #{name} to #{move.dest}.", color: :green)
65
+ rescue Move::PackageNotFoundError, Move::MultiplePackagesFoundError, ArgumentError => e
66
+ abort colorize(e.message, color: :red)
50
67
  end
51
68
 
52
69
  def update_command
@@ -100,7 +117,7 @@ module VimPK
100
117
  Remove.new(name, @options[:path]).call
101
118
 
102
119
  puts colorize("Package #{name} removed.", color: :green)
103
- rescue ArgumentError, VimPK::Remove::PackageNotFound => e
120
+ rescue ArgumentError, VimPK::Remove::PackageNotFoundError => e
104
121
  abort colorize(e.message, color: :red)
105
122
  end
106
123
  end
@@ -3,6 +3,7 @@ module VimPK
3
3
  private
4
4
 
5
5
  def colorize_diff(line)
6
+ return line if ENV["NO_COLOR"]
6
7
  case line
7
8
  when /^diff --git/
8
9
  "\e[1;34m#{line}\e[0m"
@@ -24,6 +25,7 @@ module VimPK
24
25
  end
25
26
 
26
27
  def colorize(text, color: :green)
28
+ return text if ENV["NO_COLOR"]
27
29
  case color
28
30
  when :green
29
31
  "\e[32m#{text}\e[0m"
data/lib/vimpk/move.rb ADDED
@@ -0,0 +1,41 @@
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/options.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "optparse"
2
4
 
3
5
  module VimPK
@@ -5,13 +7,15 @@ module VimPK
5
7
  attr_reader :options, :parser
6
8
 
7
9
  DEFAULT_PATH = File.expand_path("~/.vim/pack").freeze
8
- DEFAULT_TYPE = "start".freeze
9
- DEFAULT_PACK = "plugins".freeze
10
+ DEFAULT_TYPE = "start"
11
+ DEFAULT_PACK = "plugins"
10
12
 
11
13
  DefaultOptions = Struct.new(:path, :pack, :type)
12
14
 
13
- def initialize(args)
15
+ def initialize(argv)
16
+ @argv = argv
14
17
  @options = DefaultOptions.new(DEFAULT_PATH, DEFAULT_PACK, DEFAULT_TYPE)
18
+
15
19
  @parser = OptionParser.new do |parser|
16
20
  parser.banner = "Usage: #{parser.program_name} [options] [command [options]"
17
21
  parser.separator ""
@@ -50,16 +54,15 @@ module VimPK
50
54
  parser.separator ""
51
55
  parser.separator "Commands:"
52
56
  parser.separator " i|install REPO/NAME [--opt|--start] [--pack=PATH] [--path=PATH] Install a package"
57
+ parser.separator " mv|move Move a package"
53
58
  parser.separator " u|update Update all packages"
54
59
  parser.separator " rm|remove NAME Remove all occurrences of a package"
55
-
56
- begin
57
- parser.permute!(args)
58
- rescue OptionParser::MissingArgument, OptionParser::InvalidOption => e
59
- puts e.message
60
- abort("Use --help for usage information")
61
- end
62
60
  end
63
61
  end
62
+
63
+ def parse
64
+ @parser.permute!(@argv)
65
+ @options
66
+ end
64
67
  end
65
68
  end
data/lib/vimpk/remove.rb CHANGED
@@ -2,7 +2,7 @@ require "fileutils"
2
2
 
3
3
  module VimPK
4
4
  class Remove
5
- PackageNotFound = Class.new(StandardError)
5
+ PackageNotFoundError = Class.new(StandardError)
6
6
 
7
7
  def initialize(name, path)
8
8
  @name = name || raise(ArgumentError, "Package name is required")
@@ -13,7 +13,7 @@ module VimPK
13
13
  glob = Dir.glob(File.join(@path, "*", "{start,opt}", @name))
14
14
 
15
15
  if glob.empty?
16
- raise PackageNotFound, "Package #{@name} not found in #{@path}."
16
+ raise PackageNotFoundError, "Package #{@name} not found in #{@path}."
17
17
  else
18
18
  glob.each do |dir|
19
19
  FileUtils.rm_rf(dir)
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.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/vimpk.rb CHANGED
@@ -12,11 +12,12 @@ module VimPK
12
12
 
13
13
  autoload :CLI, "vimpk/cli"
14
14
  autoload :Colorizer, "vimpk/colorizer"
15
- autoload :Remove, "vimpk/remove"
16
15
  autoload :Git, "vimpk/git"
17
16
  autoload :Install, "vimpk/install"
18
17
  autoload :Job, "vimpk/job"
18
+ autoload :Move, "vimpk/move"
19
19
  autoload :Options, "vimpk/options"
20
+ autoload :Remove, "vimpk/remove"
20
21
  autoload :ThreadPool, "vimpk/thread_pool"
21
22
  autoload :Update, "vimpk/update"
22
23
  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.1.1
4
+ version: 0.2.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-15 00:00:00.000000000 Z
11
+ date: 2024-03-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -18,10 +18,8 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".overcommit.yml"
21
22
  - LICENSE.txt
22
- - README.md
23
- - Rakefile
24
- - Steepfile
25
23
  - exe/vimpk
26
24
  - lib/vimpk.rb
27
25
  - lib/vimpk/cli.rb
@@ -29,12 +27,12 @@ files:
29
27
  - lib/vimpk/git.rb
30
28
  - lib/vimpk/install.rb
31
29
  - lib/vimpk/job.rb
30
+ - lib/vimpk/move.rb
32
31
  - lib/vimpk/options.rb
33
32
  - lib/vimpk/remove.rb
34
33
  - lib/vimpk/thread_pool.rb
35
34
  - lib/vimpk/update.rb
36
35
  - lib/vimpk/version.rb
37
- - sig/vimpk.rbs
38
36
  homepage: https://github.com/pusewicz/vimpk
39
37
  licenses:
40
38
  - MIT
@@ -43,7 +41,7 @@ metadata:
43
41
  homepage_uri: https://github.com/pusewicz/vimpk
44
42
  source_code_uri: https://github.com/pusewicz/vimpk
45
43
  changelog_uri: https://github.com/pusewicz/vimpk/blob/main/CHANGELOG.md
46
- github_repo: ssh://github.com/pusewicz/vimpk
44
+ github_repo: https://github.com/pusewicz/vimpk.git
47
45
  post_install_message:
48
46
  rdoc_options: []
49
47
  require_paths:
@@ -52,7 +50,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
50
  requirements:
53
51
  - - ">="
54
52
  - !ruby/object:Gem::Version
55
- version: 3.0.0
53
+ version: 2.6.0
56
54
  required_rubygems_version: !ruby/object:Gem::Requirement
57
55
  requirements:
58
56
  - - ">="
data/README.md DELETED
@@ -1,33 +0,0 @@
1
- # VimPK
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vimpk`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- ## Installation
6
-
7
- Install the gem by executing:
8
-
9
- $ gem install vimpk
10
-
11
- ## Usage
12
-
13
- To use the gem, you can run the following command:
14
-
15
- $ vimpk
16
-
17
- ## Development
18
-
19
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
20
-
21
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
22
-
23
- ## Contributing
24
-
25
- Bug reports and pull requests are welcome on GitHub at https://github.com/pusewicz/vimpk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/pusewicz/vimpk/blob/main/CODE_OF_CONDUCT.md).
26
-
27
- ## License
28
-
29
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
30
-
31
- ## Code of Conduct
32
-
33
- Everyone interacting in the Vimpk project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pusewicz/vimpk/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "minitest/test_task"
5
-
6
- Minitest::TestTask.create
7
-
8
- require "standard/rake"
9
-
10
- task default: %i[test standard]
data/Steepfile DELETED
@@ -1,29 +0,0 @@
1
- # D = Steep::Diagnostic
2
- #
3
- # target :lib do
4
- # signature "sig"
5
- #
6
- # check "lib" # Directory name
7
- # check "Gemfile" # File name
8
- # check "app/models/**/*.rb" # Glob
9
- # # ignore "lib/templates/*.rb"
10
- #
11
- # # library "pathname" # Standard libraries
12
- # # library "strong_json" # Gems
13
- #
14
- # # configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default)
15
- # # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
16
- # # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
17
- # # configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
18
- # # configure_code_diagnostics do |hash| # You can setup everything yourself
19
- # # hash[D::Ruby::NoMethod] = :information
20
- # # end
21
- # end
22
-
23
- # target :test do
24
- # signature "sig", "sig-private"
25
- #
26
- # check "test"
27
- #
28
- # # library "pathname" # Standard libraries
29
- # end
data/sig/vimpk.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Vimpk
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end