Class: ToolOpts
- Inherits:
-
Object
- Object
- ToolOpts
- Defined in:
- lib/shed/opts/tool_opts.rb
Overview
Abstract layer for the tool shed options parsers. This sets the basic paramaters the tools respond to via the command line.
Direct Known Subclasses
ASDocPackageOpts, AssetVacuumOpts, ClassVacuumOpts, ConcreteOpts, ManifestOpts, StyleVacuumOpts
Class Method Summary collapse
-
.add_mandatory(op, config) ⇒ Object
Add all mandatory arguments to the options parser.
-
.add_optional(op, config) ⇒ Object
Add all optional arguments to the options parser.
-
.add_tail(op, out) ⇒ Object
Add tail arguments to the options parser.
-
.create_parser ⇒ Object
Create and return the options parser with the default header.
-
.default_config ⇒ Object
Default configuration hash.
-
.description ⇒ Object
A basic description of the tools use.
-
.name ⇒ Object
The name of the tool, as invoked on the command line.
-
.parse(args, out = STDOUT) ⇒ Object
Parse the arugments and return a config hash.
-
.version ⇒ Object
A version string to describe the version of the tool these options are designed to invoke.
Class Method Details
.add_mandatory(op, config) ⇒ Object
Add all mandatory arguments to the options parser.
60 61 |
# File 'lib/shed/opts/tool_opts.rb', line 60 def self.add_mandatory(op,config) end |
.add_optional(op, config) ⇒ Object
Add all optional arguments to the options parser.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/shed/opts/tool_opts.rb', line 66 def self.add_optional(op,config) op.on("-s", "--source [PATH]", String, "Path to source folder, defaults to current directory.") do |value| config[:src] = value end op.on("-o", "--output [FILE]", String, "Path to output file, defaults to #{config[:output]}.") do |value| config[:output] = value end op.on("-v", "--verbose", "Run verbosely.") do |value| config[:verbose] = value end op.on("--silent", "Supress all output.") do |value| config[:silent] = value end end |
.add_tail(op, out) ⇒ Object
Add tail arguments to the options parser.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/shed/opts/tool_opts.rb', line 87 def self.add_tail(op,out) op.on_tail("-h", "--help", "Show this help message.") do out.puts op exit end op.on_tail("--version", "Show version.") do out.puts "#{description} version #{version}" exit end end |
.create_parser ⇒ Object
Create and return the options parser with the default header.
48 49 50 51 52 53 54 55 |
# File 'lib/shed/opts/tool_opts.rb', line 48 def self.create_parser op = OptionParser.new op. = "Usage: #{name} [options]" op.separator "" op.separator "Options:" op end |
.default_config ⇒ Object
Default configuration hash.
36 37 38 39 40 41 42 43 |
# File 'lib/shed/opts/tool_opts.rb', line 36 def self.default_config { :src => ".", :output => 'output.xml', :verbose => false, :silent => false } end |
.description ⇒ Object
A basic description of the tools use.
21 22 23 |
# File 'lib/shed/opts/tool_opts.rb', line 21 def self.description 'Abstract tool from the tool shed.' end |
.name ⇒ Object
The name of the tool, as invoked on the command line.
14 15 16 |
# File 'lib/shed/opts/tool_opts.rb', line 14 def self.name ToolShed::NAME end |
.parse(args, out = STDOUT) ⇒ Object
Parse the arugments and return a config hash.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/shed/opts/tool_opts.rb', line 102 def self.parse(args,out=STDOUT) config = default_config() = create_parser() add_mandatory(,config) add_optional(,config) add_tail(,out) args = .parse!(args) config[:default] = args.shift config end |
.version ⇒ Object
A version string to describe the version of the tool these options are designed to invoke.
29 30 31 |
# File 'lib/shed/opts/tool_opts.rb', line 29 def self.version ToolShed::VERSION::STRING end |