Class: DirCatQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/dircat/cli/dircat_query.rb

Overview

DirCatQuery

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject



9
10
11
# File 'lib/dircat/cli/dircat_query.rb', line 9

def self.run
  self.new.parse_args( ARGV)
end

Instance Method Details

#parse_args(args) ⇒ Object



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
# File 'lib/dircat/cli/dircat_query.rb', line 13

def parse_args( args )
  options = {}
  opts = OptionParser.new
  opts.banner =
    "Usage: dircat_query [options] <filedircat> <command>\n" +
    "mostra informazioni su un dircat\n"

  opts.on("-h", "--help", "Print this message") do
    puts opts
    return
  end

  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
    options[:verbose] = v
  end

  rest = opts.parse( args )

  # p options
  # p ARGV

  if rest.length < 2
    puts "inserire il nome del catalogo da interrogare e il comando da eseguire"
    puts "-h to print help"
    return
  end

  cat_filename = rest[0]
  command = rest[1]

  #
  # option verbose
  #
  if options.has_key?(:verbose)
    if options[:verbose]
      $VERBOSE_LEVEL = 1
    end
  end

  s = DirCat.loadfromfile( cat_filename )

  #case command
  #else
    puts s.send( command.to_sym )
  #end
end