Class: BitClust::Subcommands::InitCommand

Inherits:
BitClust::Subcommand show all
Defined in:
lib/bitclust/subcommands/init_command.rb

Constant Summary collapse

STANDARD_PROPERTIES =
%w( encoding version )

Instance Method Summary collapse

Methods inherited from BitClust::Subcommand

#align_progress_bar_title, #error, #help, #option_error, #parse, #srcdir_root

Constructor Details

#initializeInitCommand

Returns a new instance of InitCommand.



15
16
17
18
# File 'lib/bitclust/subcommands/init_command.rb', line 15

def initialize
  super
  @parser.banner = "Usage: #{File.basename($0, '.*')} init [KEY=VALUE ...]"
end

Instance Method Details

#exec(argv, options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bitclust/subcommands/init_command.rb', line 22

def exec(argv, options)
  prefix = options[:prefix]
  db = MethodDatabase.new(prefix)
  db.init
  db.transaction {
    argv.each do |kv|
      k, v = kv.split('=', 2)
      db.propset k, v
    end
  }
  fail = false
  STANDARD_PROPERTIES.each do |key|
    unless db.propget(key)
      $stderr.puts "#{File.basename($0, '.*')}: warning: standard property `#{key}' not given"
      fail = true
    end
  end
  if fail
    $stderr.puts "---- Current Properties ----"
    db.properties.each do |key, value|
      $stderr.puts "#{key}=#{value}"
    end
  end
end