Class: BitClust::Subcommands::PropertyCommand
- Inherits:
-
BitClust::Subcommand
- Object
- BitClust::Subcommand
- BitClust::Subcommands::PropertyCommand
- Defined in:
- lib/bitclust/subcommands/property_command.rb
Instance Method Summary collapse
- #exec(argv, options) ⇒ Object
-
#initialize ⇒ PropertyCommand
constructor
A new instance of PropertyCommand.
- #parse(argv) ⇒ Object
Methods inherited from BitClust::Subcommand
#align_progress_bar_title, #error, #help, #option_error, #srcdir_root
Constructor Details
#initialize ⇒ PropertyCommand
Returns a new instance of PropertyCommand.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bitclust/subcommands/property_command.rb', line 15 def initialize super @mode = nil @parser. = "Usage: #{File.basename($0, '.*')} property [options]" @parser.on('--list', 'List all properties.') { @mode = :list } @parser.on('--get', 'Get property value.') { @mode = :get } @parser.on('--set', 'Set property value.') { @mode = :set } end |
Instance Method Details
#exec(argv, options) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bitclust/subcommands/property_command.rb', line 51 def exec(argv, ) prefix = [:prefix] db = MethodDatabase.new(prefix) case @mode when :list db.properties.each do |key, val| puts "#{key}=#{val}" end when :get argv.each do |key| puts db.propget(key) end when :set key, val = *argv db.transaction { db.propset key, val } else raise "must not happen: #{@mode}" end end |
#parse(argv) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bitclust/subcommands/property_command.rb', line 30 def parse(argv) super unless @mode error "one of (--list|--get|--set) is required" end case @mode when :list unless argv.empty? error "--list requires no argument" end when :get ; when :set unless argv.size == 2 error "--set requires just 2 arguments" end else raise "must not happen: #{@mode}" end end |