Class: Dtf::OptionsParser
- Inherits:
-
Object
- Object
- Dtf::OptionsParser
- Defined in:
- lib/dtf.rb
Overview
Dtf::OptionsParser is DTF’s command/options/parameters parsing class. It also doubles as DTF’s help system.
Constant Summary collapse
- SUB_COMMANDS =
List of all sub-commands known within the Help System
%w(create_user delete_user create_vs delete_vs setup)
Instance Method Summary collapse
-
#parse_cmds(arg) ⇒ Object
ARGV parsing method and options builder.
Instance Method Details
#parse_cmds(arg) ⇒ Object
ARGV parsing method and options builder. Method depends on Trollop gem.
Dynamically builds, and returns, the @cmd_opts Hash based on contents of @cmd, and provides the help system for options/parameters.
Returned Values: @cmd [Type: String] and @cmd_opts [Type: Hash]
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/dtf.rb', line 235 def parse_cmds(arg) # Global options default to '--version|-v' and '--help|-h' global_opts = Trollop:: do version "DTF v#{Dtf::VERSION}" <<-EOS #{version} (c) Copyright 2012 David Deryl Downey / Deryl R. Doucette. All Rights Reserved. This is free software; see the LICENSE file for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Usage: dtf -v|--version -h|--help [[sub_cmds <options>] -h|--help] Valid [sub_cmds] are: create_(user|vs), delete_(user|vs) See 'dtf [sub_cmd] -h' for each sub_cmd's details and options EOS stop_on SUB_COMMANDS end cmd = arg.shift cmd_opts = case cmd when "create_user" Trollop:: do opt(:user_name, desc="Username for new TF user - REQUIRED", opts={:type => :string, :short => '-u'}) opt(:full_name, desc="Real name for new TF user - REQUIRED", opts={:type => :string, :short => '-n'}) opt(:email_address, desc="Email address for new TF user - REQUIRED", opts={:type => :string, :short => '-e'}) end when "create_vs" Trollop:: do opt(:user_name, desc="TF user to associate this VS with - REQUIRED", opts={:type => :string, :short => '-u'}) opt(:name, desc="Name for new VS - REQUIRED", opts={:type => :string, :short => '-n'}) opt(:description, desc="Description of VS's intended use - OPTIONAL", opts={:type => :string, :short => '-d', :default => ''}) end when "delete_user" Trollop:: do opt(:user_name, desc="Username of TF user to delete - REQUIRED", opts={:type => :string, :short => '-u'}) opt(:delete_all, desc="Delete _all_ VSs this user owns", :type => :flag, :default => true) end when "delete_vs" Trollop:: do opt(:user_name, desc="Username of VS owner - REQUIRED", opts={:type => :string, :short => '-u'}) opt(:id, desc="ID of VS to be deleted - REQUIRED", opts={:type => :int, :short => '-i'}) end when "setup_dtf" Trollop:: do opt(:install, desc="Defines if should install or not", opts={:type => :flag, :default => true}) end when nil Trollop::die "No command specified! Please specify an applicable command" else Trollop::die "Unknown DTF sub-command: #{@cmd.inspect}" end return cmd, cmd_opts # Explicitly return cmd and its cmd_opts end |