Class: DirCat::CommandQuery

Inherits:
OptParseCommand::Command
  • Object
show all
Defined in:
lib/dircat/cat_on_yaml_cli/command_query.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commandObject



7
8
9
# File 'lib/dircat/cat_on_yaml_cli/command_query.rb', line 7

def self.command
  "query"
end

.descriptionObject



11
12
13
# File 'lib/dircat/cat_on_yaml_cli/command_query.rb', line 11

def self.description
  "show info about dircat catalogs"
end

.usageObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dircat/cat_on_yaml_cli/command_query.rb', line 15

def self.usage
  "  Usage: query [options] <catalog> [<method>]\n  where method can be:\n    report: show info on catalog\n    duplicates: list duplicates into catalog\n    list_dup\n    script_dup\n    fmt_simple\n\n  EOS\nend\n"

Instance Method Details

#exec(main, options, rest) ⇒ Object



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
60
61
62
63
64
65
66
67
68
69
# File 'lib/dircat/cat_on_yaml_cli/command_query.rb', line 28

def exec(main, options, rest)
  if rest.length < 1
    puts "missing catalog!"
    puts "-h to print help"
    return 0
  end

  cat_opts = {}
  cat_filename = rest[0]
  if !File.exists?(cat_filename) or File.directory?(cat_filename)
    puts "first args must be a catalogue"
    return 1
  end

  if rest.length > 1
    command = rest[1]
  else
    command = "report"
  end

  #
  # option verbose
  #
  if options.verbose
    cat_opts[:verbose_level] = 1
  end

  begin
    s = CatOnYaml.from_file(cat_filename, cat_opts)
  rescue Exception => e
    $stderr.put "cannot read catalog '#{cat_filename}' maybe it is an old version?"
    return false
  end

  if s.respond_to? command.to_sym
    puts s.send(command.to_sym)
    true
  else
    puts "unknow methods '#{command}'"
    false
  end
end