Class: Spider::CommandLine::ConfigCommand
- Defined in:
- lib/spiderfw/cmd/commands/config.rb
Instance Method Summary collapse
-
#initialize ⇒ ConfigCommand
constructor
A new instance of ConfigCommand.
Constructor Details
#initialize ⇒ ConfigCommand
Returns a new instance of ConfigCommand.
6 7 8 9 10 11 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/spiderfw/cmd/commands/config.rb', line 6 def initialize super( 'config', true, true ) @short_desc = _("Manage configuration") list = CmdParse::Command.new( 'list', false ) list.short_desc = _("List configuration options") list. = CmdParse::OptionParserWrapper.new do |opt| opt.on("--info", _("Show info"), "-i"){ |i| @info = true } end list.set_execution_block do |args| require 'spiderfw/spider' Spider.init_base search = args.first max_len = 0 opts = Spider.config. opts.each{ |o| max_len = o.length if o.length > max_len } opts.sort.each{ |o| next if search && o.index(search) != 0 str = o.ljust(max_len + 2) if @info option = Spider.config.option(o) str += " #{option[:description]}" if option end puts str } end self.add_command(list) info = CmdParse::Command.new('info', false) info.short_desc = _("Get information about a configuration option") info.set_execution_block do |args| require 'spiderfw/spider' Spider.init_base option = Spider.config.option(args.first) if option && option[:params] print args[0] print ":\n"+option[:description]+"\n" if option[:description] && !option[:description].empty? puts puts "#{( _('Type') +':').ljust(10)} #{option[:params][:type]}" if option[:params][:type] default_str = nil if default = option[:params][:default] default_str = default.is_a?(Proc) ? _('Dynamic') : default end puts "#{( _('Default') +':').ljust(10)} #{default_str}" if default_str if choices = option[:params][:choices] choices = choices.call if choices.is_a?(Proc) puts "#{( _('Choices') +':').ljust(10)} #{choices.join(', ')}" end else puts _("Configuration option not found") end end self.add_command(info) get = CmdParse::Command.new('get', false) get.short_desc = _("Get the current value of a configuration option") get.set_execution_block do |args| require 'spiderfw/spider' Spider.init_base puts Spider.conf.get(args.first) end self.add_command(get) set = CmdParse::Command.new('set', false) set.short_desc = _("Set the value of a configuration option") set.set_execution_block do |args| require 'spiderfw/spider' require 'lib/spiderfw/config/configuration_editor' Spider.init_base editor = Spider.config.get_editor editor.set(*args) editor.save end self.add_command(set) end |