class ToolOpts
Abstract layer for the tool shed options parsers. This sets the basic paramaters the tools respond to via the command line.
Public Class Methods
add_mandatory(op,config)
click to toggle source
Add all mandatory arguments to the options parser.
# File lib/shed/opts/tool_opts.rb, line 60 def self.add_mandatory(op,config) end
add_optional(op,config)
click to toggle source
Add all optional arguments to the options parser.
# 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)
click to toggle source
Add tail arguments to the options parser.
# 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()
click to toggle source
Create and return the options parser with the default header.
# File lib/shed/opts/tool_opts.rb, line 48 def self.create_parser op = OptionParser.new op.banner = "Usage: #{name} [options]" op.separator "" op.separator "Options:" op end
default_config()
click to toggle source
Default configuration hash.
# File lib/shed/opts/tool_opts.rb, line 36 def self.default_config { :src => ".", :output => 'output.xml', :verbose => false, :silent => false } end
description()
click to toggle source
A basic description of the tools use.
# File lib/shed/opts/tool_opts.rb, line 21 def self.description 'Abstract tool from the tool shed.' end
name()
click to toggle source
The name of the tool, as invoked on the command line.
# File lib/shed/opts/tool_opts.rb, line 14 def self.name ToolShed::NAME end
parse(args,out=STDOUT)
click to toggle source
Parse the arugments and return a config hash.
# File lib/shed/opts/tool_opts.rb, line 102 def self.parse(args,out=STDOUT) config = default_config() options = create_parser() add_mandatory(options,config) add_optional(options,config) add_tail(options,out) args = options.parse!(args) config[:default] = args.shift config end
version()
click to toggle source
A version string to describe the version of the tool these options are designed to invoke.
# File lib/shed/opts/tool_opts.rb, line 29 def self.version ToolShed::VERSION::STRING end