Class: LsAll::LsAllOpts

Inherits:
Object
  • Object
show all
Defined in:
lib/ls_all/ls_all_opts.rb

Class Method Summary collapse

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.
      options = OpenStruct.new

      options.sort  = :normal
      options.depth = 0
      options.count = false
      options.path  = '.'

      opts = OptionParser.new do |opts|
         opts.banner = "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|
            options.depth = n
         end

         opts.on("-c", "--count", "return file count for max depth of folder" ) do |n|
            options.count = n
      end
   end

   options.leftovers = opts.parse!(args)
   if options.leftovers.size > 0
      if File.exists?(  File.expand_path( options.leftovers[0] ) )
         options.path = File.expand_path( options.leftovers[0] )
      end
   end

   return options

end