Skip to content

Commit

Permalink
feat: Add support for the list command
Browse files Browse the repository at this point in the history
  • Loading branch information
pusewicz committed Mar 17, 2024
1 parent a413c69 commit 33e8dd1
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/vimpk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Error < StandardError; end
autoload :Git, "vimpk/git"
autoload :Install, "vimpk/install"
autoload :Job, "vimpk/job"
autoload :List, "vimpk/list"
autoload :Move, "vimpk/move"
autoload :Options, "vimpk/options"
autoload :Remove, "vimpk/remove"
Expand Down
24 changes: 24 additions & 0 deletions lib/vimpk/list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "fileutils"

module VimPK
class List
PackageNotFoundError = Class.new(StandardError)

attr_reader :dest

def initialize(options)
@path = options.path
@pack = options.pack || "*"
@type = options.type || "{start,opt}"
end

def call
pattern = File.join(@path, @pack, @type, "*")
glob = Dir.glob(pattern)

raise PackageNotFoundError, "No packages were found in #{pattern}." if glob.empty?

glob
end
end
end
3 changes: 2 additions & 1 deletion lib/vimpk/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def initialize(argv)
parser.separator ""
parser.separator "Commands:"
parser.separator " i|install REPO/NAME [--opt|--start] [--pack=PATH] [--path=PATH] Install a package"
parser.separator " mv|move Move a package"
parser.separator " l|list [--opt|--start] [--pack=PATH] [--path=PATH] List packages"
parser.separator " mv|move NAME [--opt|--start] [--pack=PATH] Move a package"
parser.separator " u|update Update all packages"
parser.separator " rm|remove NAME Remove all occurrences of a package"
end
Expand Down
Empty file.
Empty file.
16 changes: 16 additions & 0 deletions test/test_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class TestCLI < Minitest::Test
def test_valid_command
assert_equal :install_command, VimPK::CLI.new(["i"]).command
assert_equal :install_command, VimPK::CLI.new(["install"]).command
assert_equal :list_command, VimPK::CLI.new(["l"]).command
assert_equal :list_command, VimPK::CLI.new(["list"]).command
assert_equal :move_command, VimPK::CLI.new(["mv"]).command
assert_equal :move_command, VimPK::CLI.new(["move"]).command
assert_equal :update_command, VimPK::CLI.new(["u"]).command
Expand Down Expand Up @@ -43,4 +45,18 @@ def test_call_help

assert_match(/Usage:/, out)
end

def test_call_list
using_pack_path do |path|
out, _err = capture_io do
exception = assert_raises(SystemExit) { VimPK::CLI.new(["list", "--path", path]).call }
assert_equal(0, exception.status)
end

assert_equal(<<~LIST, out)
#{path}/colors/opt/pretty
#{path}/plugins/start/someplug
LIST
end
end
end
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "vimpk"
require "fileutils"

require "minitest/autorun"

ENV["NO_COLOR"] = "1"

def using_pack_path
Dir.mktmpdir do |dir|
FileUtils.cp_r("test/fixtures/vim/pack/.", dir)
yield dir
end
end

0 comments on commit 33e8dd1

Please sign in to comment.