Revision 38e5c5db
Added by Marc Dequènes about 15 years ago
- ID 38e5c5db43a5c6082ff3f271426f5889810e5b04
bin/shadowwalker | ||
---|---|---|
|
||
protected
|
||
|
||
def params_shift_location(args)
|
||
raise SyntaxError, _("no location name given") if args.empty?
|
||
|
||
location = args.shift.downcase
|
||
raise SyntaxError, _("bad location") unless location =~ /^([a-zA-Z]+)\/(.+)$/
|
||
loc_obj_hdl = $1
|
||
loc_item_hdl = $2
|
||
|
||
split_args = [loc_obj_hdl, loc_item_hdl]
|
||
loc_obj_klass = params_shift_object(split_args)
|
||
loc_item = params_shift_item(loc_obj_klass, split_args)
|
||
|
||
[loc_obj_klass, loc_item]
|
||
def params_shift_item_handle_full_handle(args, fetch_item = true, name = "item full-handle")
|
||
raise SyntaxError, _("no %s given") % name if args.empty?
|
||
|
||
full_handle = args.shift.downcase
|
||
raise SyntaxError, _("bad %s") % name unless full_handle =~ /^([a-zA-Z]+)\/(.+)$/
|
||
obj_hdl = $1
|
||
item_hdl = $2
|
||
|
||
split_args = [obj_hdl, item_hdl]
|
||
obj_klass = params_shift_object_handle(split_args)
|
||
if fetch_item
|
||
item = params_shift_item_handle(obj_klass, split_args)
|
||
[obj_klass, item]
|
||
else
|
||
[obj_klass, item_hdl]
|
||
end
|
||
end
|
||
|
||
def params_shift_object(args)
|
||
def params_shift_object_handle(args)
|
||
raise SyntaxError, _("no object name given") if args.empty?
|
||
|
||
obj_hdl = args.shift.downcase.singularize
|
||
... | ... | |
obj_klass
|
||
end
|
||
|
||
def params_shift_item(obj_klass, args)
|
||
def params_shift_item_handle(obj_klass, args)
|
||
raise SyntaxError, _("no item name given") if args.empty?
|
||
|
||
attr_list = ["*"]
|
||
... | ... | |
puts " - #{obj_name}"
|
||
end
|
||
else
|
||
obj_klass = params_shift_object([obj_hdl])
|
||
obj_klass = params_shift_object_handle([obj_hdl])
|
||
|
||
if args.empty?
|
||
obj_human_name = Translator.translate_object_name(obj_hdl)
|
||
... | ... | |
|
||
self.short_desc = "show item information"
|
||
self.usages_params = [
|
||
"<object> <item>",
|
||
"<object> <item> <field>#? [<filename>]",
|
||
"<object> <item> <field>[#<index>] [<filename>]"
|
||
"<object>/<item>",
|
||
"<object>/<item> <field>#? [<filename>]",
|
||
"<object>/<item> <field>[#<index>] [<filename>]"
|
||
]
|
||
self.options = CmdParse::OptionParserWrapper.new do |opt|
|
||
opt.on( '-f', '--family', 'Display family members.' ) { $program_options[:show_family_members] = true }
|
||
... | ... | |
def execute(args)
|
||
super
|
||
|
||
obj_klass = params_shift_object(args)
|
||
item = params_shift_item(obj_klass, args)
|
||
obj_klass, item = params_shift_item_handle_full_handle(args)
|
||
|
||
if args.empty?
|
||
$program_options[:skip_binary] = true
|
||
... | ... | |
raise PreProcessingError, _("No such field '%s' in object '%s'") % [field_name, obj_klass.handle]
|
||
end
|
||
unless item.attribute_present?(field_name)
|
||
raise PreProcessingError, _("Field '%s' in item '%s/%s' is not present") %
|
||
[field_name, obj_klass.handle, item.name]
|
||
raise PreProcessingError, _("Field '%s' in item '%s' is not present") %
|
||
[field_name, item.full_handle]
|
||
end
|
||
|
||
field_data = item.send(field_name, true)
|
||
... | ... | |
|
||
self.short_desc = "show skeleton items tree"
|
||
self.usages_params = [
|
||
"[<location>]"
|
||
"[<location-item-full-handle>]"
|
||
]
|
||
self.options = CmdParse::OptionParserWrapper.new do |opt|
|
||
opt.on( '-a', '--all', 'Display all objects in the tree.' ) { $program_options[:tree_all_objects] = true }
|
||
... | ... | |
|
||
search_base = nil
|
||
unless args.empty?
|
||
loc_obj_klass, loc_item = params_shift_location(args)
|
||
loc_obj_klass, loc_item = params_shift_item_handle_full_handle(args, true, "location full-handle")
|
||
search_base = loc_item.dn
|
||
end
|
||
|
||
... | ... | |
end
|
||
cmdparser.add_command(TreeCommand.new)
|
||
|
||
class ModCommand < Command
|
||
class ModifyCommand < Command
|
||
def initialize
|
||
super('mod', false)
|
||
super('modify', false)
|
||
|
||
self.short_desc = "Modify attributes of an item"
|
||
self.usages_params = [
|
||
"<object> <item> (<field>|<relation>|:aspects)(=|+=|-=)<value> [(<field>|<relation>|:aspects)(=|+=|-=)<value>] ..."
|
||
"<item-full-handle> (<field>|<relation>|:aspects)(=|+=|-=)<value> [(<field>|<relation>|:aspects)(=|+=|-=)<value>] ..."
|
||
]
|
||
end
|
||
|
||
def execute(args)
|
||
super
|
||
|
||
obj_klass = params_shift_object(args)
|
||
item = params_shift_item(obj_klass, args)
|
||
obj_klass, item = params_shift_item_handle_full_handle(args)
|
||
|
||
modification_done = false
|
||
args.each do |mod_info|
|
||
... | ... | |
end
|
||
end
|
||
end
|
||
cmdparser.add_command(ModCommand.new)
|
||
cmdparser.add_command(ModifyCommand.new)
|
||
|
||
class DelCommand < Command
|
||
class DeleteCommand < Command
|
||
def initialize
|
||
super('del', false)
|
||
super('delete', false)
|
||
|
||
self.short_desc = "Delete an item"
|
||
self.usages_params = [
|
||
"<object> <item>"
|
||
"<item-full-handle>"
|
||
]
|
||
self.options = CmdParse::OptionParserWrapper.new do |opt|
|
||
opt.on( '-r', '--recursive', 'Delete object and all children recursively.' ) { $program_options[:recursive_delete] = true }
|
||
... | ... | |
def execute(args)
|
||
super
|
||
|
||
obj_klass = params_shift_object(args)
|
||
item = params_shift_item(obj_klass, args)
|
||
obj_klass, item = params_shift_item_handle_full_handle(args)
|
||
|
||
if $program_options[:recursive_delete]
|
||
item.delete_recursive
|
||
... | ... | |
puts "Deletion done."
|
||
end
|
||
end
|
||
cmdparser.add_command(DelCommand.new)
|
||
cmdparser.add_command(DeleteCommand.new)
|
||
|
||
class CreateCommand < Command
|
||
def initialize
|
||
... | ... | |
|
||
self.short_desc = "Create an item"
|
||
self.usages_params = [
|
||
"<object> <new_item> <location> [<field>=<value>] ..."
|
||
"<new-item-full-handle> <parent-item-full-handle> [<field>=<value>] ..."
|
||
]
|
||
end
|
||
|
||
def execute(args)
|
||
super
|
||
|
||
obj_klass = params_shift_object(args)
|
||
|
||
raise SyntaxError, _("no item name given") if args.empty?
|
||
item_hdl = args.shift.downcase
|
||
|
||
loc_obj_klass, loc_item = params_shift_location(args)
|
||
obj_klass, item_hdl = params_shift_item_handle_full_handle(args)
|
||
loc_obj_klass, loc_item = params_shift_item_handle_full_handle(args, true, "parent full-handle")
|
||
|
||
item = obj_klass.new(item_hdl)
|
||
item.base = loc_item.dn_obj - obj_klass.base_obj
|
Also available in: Unified diff
[evol] introduce item 'full-handle' and reorganize command arguments, and renamed commands