Class: SimpleCataloger::CliServer

Inherits:
Object
  • Object
show all
Defined in:
lib/dircat/cat_on_sqlite_cli/cli_server.rb

Overview

Build a catalogue starting from a directory

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject



8
9
10
# File 'lib/dircat/cat_on_sqlite_cli/cli_server.rb', line 8

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

Instance Method Details

#parse_args(argv) ⇒ Object



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
60
61
62
# File 'lib/dircat/cat_on_sqlite_cli/cli_server.rb', line 12

def parse_args( argv )
  options = { :verbose => true, :force => false }
  opts = OptionParser.new
  opts.banner << " <catalog name>\n"
  opts.banner << "launch a webs server to browse the content of <catalog name>\n";
  opts.banner << "\n"

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

  opts.on("--version", "show the simple catalog version") do
    puts "simple catalog version #{SimpleCatalog::version}"
    return 0
  end

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

  rest = opts.parse(argv)

  if rest.length < 1
    puts "too few arguments"
    puts "-h to print help"
    return 0
  end

  catalog_name = rest[0]
  cat_opts = {}

  #
  # option verbose
  #

  if options.has_key?(:verbose)
    if options[:verbose]
      cat_opts[:verbose_level] = 1
    end
  end

  #
  # main
  #

  catalog = CatOnSqlite.new(catalog_name)
  WebServer.run! :host => 'localhost', :port => 9091, :catalog => catalog

  0
end