Class: VimPK::Options
- Inherits:
-
Object
- Object
- VimPK::Options
- Defined in:
- lib/vimpk/options.rb
Defined Under Namespace
Classes: DefaultOptions
Constant Summary collapse
- DEFAULT_PATH =
File.("~/.vim/pack").freeze
- DEFAULT_TYPE =
"start"- DEFAULT_PACK =
"plugins"
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Options
constructor
A new instance of Options.
- #parse ⇒ Object
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 = DefaultOptions.new(DEFAULT_PATH, nil, nil, DEFAULT_PACK, DEFAULT_TYPE) @parser = OptionParser.new do |parser| parser. = "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| [:pack] = pack end parser.on("--path=PATH", String, "Path to Vim's pack directory (#{DEFAULT_PATH})") do |path| path = File.(path) unless File.directory?(path) abort("Error: #{path} is not a directory") end [:path] = path end parser.on("--opt", "Install package as an optional plugin") do [:type] = "opt" end parser.on("--start", "Install package as a start plugin (default)") do [: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
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/vimpk/options.rb', line 7 def end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
7 8 9 |
# File 'lib/vimpk/options.rb', line 7 def parser @parser end |
Instance Method Details
#parse ⇒ Object
64 65 66 67 |
# File 'lib/vimpk/options.rb', line 64 def parse @parser.permute!(@argv) end |