Class: LsAll::LsAllOpts
- Inherits:
-
Object
- Object
- LsAll::LsAllOpts
- Defined in:
- lib/ls_all/ls_all_opts.rb
Class Method Summary collapse
-
.parse(args) ⇒ Object
Return a structure describing the options.
Class Method Details
.parse(args) ⇒ Object
Return a structure describing the options.
9 10 11 12 13 14 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 |
# File 'lib/ls_all/ls_all_opts.rb', line 9 def self.parse(args) #VERSION is held in top level LSAll::VERSION @VERSION = VERSION # The options specified on the command line will be collected in *options*. # We set default values here. = OpenStruct.new .sort = :normal .depth = 0 .count = false .path = '.' opts = OptionParser.new do |opts| opts. = "Usage: #{__FILE__} [options]" opts.separator "" opts.separator "Common options:" # No argument, shows at tail. This will print an options summary. opts.on("-h", "--help", "Show this message") do puts opts exit end # Another typical switch to print the version. opts.on("--version", "Show version") do puts "Version #{@VERSION}" exit end opts.separator "" opts.separator "Specific options:" opts.on("-d", "--max-depth N", Integer, "Maximum traversal depth") do |n| .depth = n end opts.on("-c", "--count", "return file count for max depth of folder" ) do |n| .count = n end end .leftovers = opts.parse!(args) if .leftovers.size > 0 if File.exists?( File.( .leftovers[0] ) ) .path = File.( .leftovers[0] ) end end return end |