Ignore:
Timestamp:
8/4/2010 1:09:55 AM (22 months ago)
Author:
lowjoel
Message:

Do not assume that only one configurer can handle every command line-argument. Always check for the situation where two configurers can handle the same argument; detect the error, display a message and exit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser/Program.cs

    r2221 r2227  
    294294where action is 
    295295  help                Show this help message. 
    296   addtask             Adds tasks to the current task list. 
     296  addtask             Adds a task to the current task list. 
    297297  querymethods        Lists all registered Erasure methods. 
    298298  importtasklist      Imports an Eraser Task list to the current user's Task 
     
    422422            foreach (string argument in arguments.PositionalArguments) 
    423423            { 
    424                 bool processed = false; 
     424                ErasureTarget selectedTarget = null; 
     425 
     426                //Iterate over every defined erasure target 
    425427                foreach (ErasureTarget target in ManagerLibrary.Instance.ErasureTargetRegistrar) 
    426                     if (target.Configurer.ProcessArgument(argument)) 
     428                { 
     429                    //See if this argument can be handled by the target's configurer 
     430                    IErasureTargetConfigurer configurer = target.Configurer; 
     431                    if (configurer.ProcessArgument(argument)) 
    427432                    { 
    428                         target.Method = method; 
    429                         task.Targets.Add(target); 
    430                         processed = true; 
    431                         break; 
     433                        //Check whether a target has been set (implicitly: check whether two 
     434                        //configurers can process the argument) 
     435                        if (selectedTarget == null) 
     436                        { 
     437                            configurer.SaveTo(target); 
     438                            selectedTarget = target; 
     439                        } 
     440                        else 
     441                        { 
     442                            //Yes, it is an ambiguity. Throw an error. 
     443                            throw new InvalidOperationException("Ambiguous argument: {0} can be " + 
     444                                "handled by more than one erasure target."); 
     445                        } 
    432446                    } 
    433  
    434                 if (!processed) 
     447                } 
     448 
     449                //Check whether a target has been made from parsing the entry. 
     450                if (selectedTarget == null) 
    435451                { 
    436452                    Console.WriteLine(S._("Unknown argument: {0}, skipped.", argument)); 
    437                     continue; 
     453                } 
     454                else 
     455                { 
     456                    selectedTarget.Method = method; 
     457                    task.Targets.Add(selectedTarget); 
    438458                } 
    439459            } 
Note: See TracChangeset for help on using the changeset viewer.