Class: SimpleCataloger::CmdCreate

Inherits:
OptParseCommand::Command
  • Object
show all
Defined in:
lib/dircat/cat_on_sqlite_cli/cmd_create.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commandObject



7
8
9
# File 'lib/dircat/cat_on_sqlite_cli/cmd_create.rb', line 7

def self.command
  "create"
end

.descriptionObject



11
12
13
# File 'lib/dircat/cat_on_sqlite_cli/cmd_create.rb', line 11

def self.description
  "create a catalog"
end

.usageObject



15
16
17
18
# File 'lib/dircat/cat_on_sqlite_cli/cmd_create.rb', line 15

def self.usage
  "#{command} <catalog name> <directory>\n" +
  "Create a catalog with name <catalog name> starting from structure of <directory>"
end

Instance Method Details

#defaults(options) ⇒ Object



20
21
22
23
# File 'lib/dircat/cat_on_sqlite_cli/cmd_create.rb', line 20

def defaults(options)
  options.force = false
  options
end

#exec(main, options, rest) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dircat/cat_on_sqlite_cli/cmd_create.rb', line 30

def exec(main, options, rest)
  if rest.length < 2
    puts "too few arguments"
    puts "-h to print help"
    return 0
  end
  catalog_name = rest[0]
  catalog_dirname = rest[1]
  catalog_dirname = File.expand_path(catalog_dirname)

  if not FileTest.directory?(catalog_dirname)
    puts "'#{catalog_dirname}' not exists or is not a directory"
    return 0
  end

  begin
    catalog = SimpleCataloger::CatOnSqlite.new(catalog_name)
    catalog.create(catalog_dirname)
    catalog.update
  rescue SimpleCataloger::SimpleCatalogerError => e
    puts e.message
  end
  0
end

#option_parser(options) ⇒ Object



25
26
27
28
# File 'lib/dircat/cat_on_sqlite_cli/cmd_create.rb', line 25

def option_parser(options)
  parser = super(options)
  parser
end