Class: Modname::Driver
Overview
Driver class handles command-line argument parsing and execution
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ Driver
constructor
A new instance of Driver.
-
#parse(args) ⇒ Object
parse out arguments.
-
#run(args) ⇒ Object
parse user arguments.
Methods included from Modder
confirm?, execute, #exts, files, finish, parse, #regex, rename, rename_base, status, #undercase_ext, undercase_ext_get, undercase_ext_set
Constructor Details
#initialize ⇒ Driver
Returns a new instance of Driver.
23 24 25 26 |
# File 'lib/modname.rb', line 23 def initialize @options = { force: false, recurse: false } @transfer = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
21 22 23 |
# File 'lib/modname.rb', line 21 def @options end |
Instance Method Details
#parse(args) ⇒ Object
parse out arguments
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/modname.rb', line 53 def parse(args) opts = { cmd: 'file', args: [] } args.each do |opt| case opt when '-f' @options[:force] = true when '-r' @options[:recurse] = true when '-e', '--ext' opts[:cmd] = 'ext' when '-h', '--help' opts[:cmd] = 'help' when '-v', '--version' opts[:cmd] = 'version' else # command argument opts[:args] << opt end end opts end |
#run(args) ⇒ Object
parse user arguments
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/modname.rb', line 29 def run(args) if args.empty? puts Modname::HELP_BANNER else opts = parse args cmd = opts[:cmd] case cmd when 'file' regex opts[:args] when 'ext' exts opts[:args] when 'help' puts Modname::V_HELP_BANNER when 'version' puts Modname::VERSION end end end |