Class: VimPK::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/vimpk/options.rb

Defined Under Namespace

Classes: DefaultOptions

Constant Summary collapse

DEFAULT_PATH =
File.expand_path("~/.vim/pack").freeze
DEFAULT_TYPE =
"start"
DEFAULT_PACK =
"plugins"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Options

Returns a new instance of Options.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vimpk/options.rb', line 15

def initialize(argv)
  @argv = argv
  @options = DefaultOptions.new(DEFAULT_PATH, nil, nil, DEFAULT_PACK, DEFAULT_TYPE)

  @parser = OptionParser.new do |parser|
    parser.banner = "Usage: #{parser.program_name} [options] [command [options]"
    parser.separator ""
    parser.separator "Options:"

    parser.on("--pack=PATH", String, "Name of the pack (#{DEFAULT_PACK})") do |pack|
      @options[:pack] = pack
    end

    parser.on("--path=PATH", String, "Path to Vim's pack directory (#{DEFAULT_PATH})") do |path|
      path = File.expand_path(path)
      unless File.directory?(path)
        abort("Error: #{path} is not a directory")
      end
      @options[:path] = path
    end

    parser.on("--opt", "Install package as an optional plugin") do
      @options[:type] = "opt"
    end

    parser.on("--start", "Install package as a start plugin (default)") do
      @options[:type] = "start"
    end

    parser.on("-h", "--help", "Show this help message") do
      puts parser
      exit
    end

    parser.on("-v", "--version", "Show version") do
      puts VimPK::VERSION
      exit
    end

    parser.separator ""
    parser.separator "Commands:"
    parser.separator "        i|install REPO/NAME [--opt|--start] [--pack=PATH] [--path=PATH] Install 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
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/vimpk/options.rb', line 7

def options
  @options
end

#parserObject (readonly)

Returns the value of attribute parser.



7
8
9
# File 'lib/vimpk/options.rb', line 7

def parser
  @parser
end

Instance Method Details

#parseObject



64
65
66
67
# File 'lib/vimpk/options.rb', line 64

def parse
  @parser.permute!(@argv)
  @options
end