Sha256: fc7c93e45afe84fba9fcfc4a0156c7589c03e11b2d8f5a50e1bacfa4e9928fc4

Contents?: true

Size: 1.61 KB

Versions: 19

Compression:

Stored size: 1.61 KB

Contents

require 'pathname'
require 'erb'
require 'find'
require 'pp'
require 'optparse'
require 'yaml'

require 'bitclust'
require 'bitclust/subcommand'

module BitClust
  module Subcommands
    class PropertyCommand < Subcommand
      def initialize
        super
        @mode = nil
        @parser.banner = "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

      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

      def exec(argv, options)
        prefix = options[: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
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bitclust-core-1.2.6 lib/bitclust/subcommands/property_command.rb
bitclust-core-1.2.5 lib/bitclust/subcommands/property_command.rb
bitclust-core-1.2.4 lib/bitclust/subcommands/property_command.rb
bitclust-core-1.2.3 lib/bitclust/subcommands/property_command.rb
bitclust-core-1.2.2 lib/bitclust/subcommands/property_command.rb
bitclust-core-1.2.1 lib/bitclust/subcommands/property_command.rb
bitclust-core-1.2.0 lib/bitclust/subcommands/property_command.rb
bitclust-core-1.1.1 lib/bitclust/subcommands/property_command.rb
bitclust-core-1.1.0 lib/bitclust/subcommands/property_command.rb
bitclust-core-1.0.0 lib/bitclust/subcommands/property_command.rb
bitclust-core-0.9.6 lib/bitclust/subcommands/property_command.rb
bitclust-core-0.9.5 lib/bitclust/subcommands/property_command.rb
bitclust-core-0.9.4 lib/bitclust/subcommands/property_command.rb
bitclust-core-0.9.3 lib/bitclust/subcommands/property_command.rb
bitclust-core-0.9.2 lib/bitclust/subcommands/property_command.rb
bitclust-core-0.9.1 lib/bitclust/subcommands/property_command.rb
bitclust-core-0.9.0 lib/bitclust/subcommands/property_command.rb
bitclust-core-0.8.0 lib/bitclust/subcommands/property_command.rb
bitclust-core-0.7.0 lib/bitclust/subcommands/property_command.rb