commit 016427dd02ba652aba3281235e512f73f3650fb5
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Sat Oct 9 20:59:12 2010 +0200

    [evol] allow specifying a file content as value in the command line for search and modify commands (closes #149)

diff --git a/bin/shadowwalker b/bin/shadowwalker
index 8802c74..dc1a3c1 100755
--- a/bin/shadowwalker
+++ b/bin/shadowwalker
@@ -329,7 +329,7 @@ class ModifyCommand < Command
 
     self.short_desc = "Modify attributes of an item"
     self.usages_params = [
-                          "<item-full-handle> [:parent=<value>] (<field>|<relation>|:aspects)(=|+=|-=)<value> [(<field>|<relation>|:aspects)(=|+=|-=)<value>] ..."
+                          "<item-full-handle> [:parent=<value>] (<field>|<relation>|:aspects)[@](=|+=|-=)<value> [(<field>|<relation>|:aspects)(=|+=|-=)<value>] ..."
                          ]
   end
 
@@ -409,7 +409,7 @@ class SearchCommand < Command
 
     self.short_desc = "Search items"
     self.usages_params = [
-                          "[:objects=<object>[,<object>]...] [:aspects=<aspect>[,<aspect>]...] [[filter:]<field>=<value>] [:parents|:siblings|:children|:ancestors|:successors=<item-full-handle>[,<item-full-handle>]] ..."
+                          "[:objects[@]=<object>[,<object>]...] [:aspects[@]=<aspect>[,<aspect>]...] [[filter:]<field>[@]=<value>] [:parents|:siblings|:children|:ancestors|:successors[@]=<item-full-handle>[,<item-full-handle>]] ..."
                          ]
     self.usage_extra_info = "Criterias are AND-ed, but lists of values for a criteria are OR-ed."
   end
diff --git a/lib/ldap_shadows/elements/object.rb b/lib/ldap_shadows/elements/object.rb
index 75fcf4e..0fbdec6 100644
--- a/lib/ldap_shadows/elements/object.rb
+++ b/lib/ldap_shadows/elements/object.rb
@@ -317,17 +317,7 @@ module Elements
         raise PreProcessingError, _("The field '%s' cannot be modified (read only)") % field
       end
 
-      if attr_info[:binary]
-        unless File.exists?(val)
-          raise PreProcessingError, _("The field '%s' contains binary data, you must provide a filename instead of a direct value") % field
-        end
-
-        begin
-          val = File.read(val)
-        rescue
-          raise PreProcessingError, _("The file for the binary field '%s' cannot be read: ") % [field, $!]
-        end
-      elsif attr_info[:syntax] == "1.3.6.1.4.1.1466.115.121.1.12"
+      if attr_info[:syntax] == "1.3.6.1.4.1.1466.115.121.1.12"
         if val =~ FULL_HANDLE_PATTERN
           obj_hdl = $1.downcase
           item_hdl = $2
diff --git a/lib/ldap_shadows/manipulation_helper.rb b/lib/ldap_shadows/manipulation_helper.rb
index 9ba716f..9185eee 100644
--- a/lib/ldap_shadows/manipulation_helper.rb
+++ b/lib/ldap_shadows/manipulation_helper.rb
@@ -19,20 +19,40 @@
 
 module LdapShadows
   module Manipulation
-    # hyphens are permitted by RFC2251, but disallowed for method named
+    # hyphens are permitted by RFC2251, but disallowed for method names
     TEXTUI_KEY_PATTERN = "(?:[a-zA-Z]*:)?[a-zA-Z][a-zA-Z0-9]*"
 
+    def self.prepare_string_part(key, op_modifier, op, val)
+      case op_modifier
+      when '@'
+        unless File.exists?(val)
+          raise PreProcessingError, _("The file for key '%s' does not exist") % key
+       end
+
+        begin
+          val = File.read(val)
+        rescue
+          raise PreProcessingError, _("The file for key '%s' cannot be read: ") % [key, $!]
+        end
+      end
+
+      val
+    end
+
     def self.item_modify_from_strings(item, str_list)
       str_list = [str_list] unless str_list.is_a? Array
 
       modification_done = false
       str_list.each do |str|
-        unless str =~ /^(#{TEXTUI_KEY_PATTERN})(=|\+=|-=)(.*)$/
+        unless str =~ /^(#{TEXTUI_KEY_PATTERN})(@)?(=|\+=|-=)(.*)$/
           raise SyntaxError, _("modification parameter '%s' is invalid") % str
         end
         key = $1
-        op = $2
-        val = $3
+        op_modifier = $2
+        op = $3
+        val = $4
+
+        val = prepare_string_part(key, op_modifier, op, val)
 
         mod_done = item.modify(key, op, val)
         modification_done ||= mod_done
@@ -49,12 +69,15 @@ module LdapShadows
       ldap_search_exclude =Set.new
       ldap_search_fields_post = Set.new
       str_list.each do |str|
-        unless str =~ /^(#{TEXTUI_KEY_PATTERN})(=|~=)(.*)$/
+        unless str =~ /^(#{TEXTUI_KEY_PATTERN})(@)?(=|~=)(.*)$/
           raise SyntaxError, _("search parameter '%s' is invalid") % str
         end
         key = $1
-        op = $2
-        val = $3
+        op_modifier = $2
+        op = $3
+        val = $4
+
+        val = prepare_string_part(key, op_modifier, op, val)
 
         if key.index(":")
           type, field = key.split(":")
