This is the mail archive of the frysk-cvs@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[SCM] master: Allow abbreviated long options.


The branch, master has been updated
       via  7f9bb90dbeec8a3db40e22541347fdd9730e304f (commit)
      from  fb20dde8b9c322b77e642ba0d6f360deb3e9ee13 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 7f9bb90dbeec8a3db40e22541347fdd9730e304f
Author: Andrew Cagney <cagney@redhat.com>
Date:   Wed Nov 14 13:03:05 2007 -0500

    Allow abbreviated long options.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-14  Andrew Cagney  <cagney@redhat.com>
    
    	* TestParameterizedCommand.java (testShortAmbigiousOption()): New.
    	(testShortUnambigiousOption()): New.
    	* ParameterizedCommand.java: Allow shortened form of options.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/hpd/ChangeLog                     |    4 ++++
 frysk-core/frysk/hpd/ParameterizedCommand.java     |   14 +++++++++++---
 frysk-core/frysk/hpd/TestParameterizedCommand.java |   16 ++++++++++++++++
 3 files changed, 31 insertions(+), 3 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index b833658..da41ea0 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,5 +1,9 @@
 2007-11-14  Andrew Cagney  <cagney@redhat.com>
 
+	* TestParameterizedCommand.java (testShortAmbigiousOption()): New.
+	(testShortUnambigiousOption()): New.
+	* ParameterizedCommand.java: Allow shortened form of options.
+	
 	* TestCompletionFactory.java: New.
 	* Input.java (base(int)): New.
 	(cursor(int,int)): New.
diff --git a/frysk-core/frysk/hpd/ParameterizedCommand.java b/frysk-core/frysk/hpd/ParameterizedCommand.java
index 91329ea..e7289b2 100644
--- a/frysk-core/frysk/hpd/ParameterizedCommand.java
+++ b/frysk-core/frysk/hpd/ParameterizedCommand.java
@@ -67,9 +67,17 @@ abstract class ParameterizedCommand extends Command {
     }
 
     private CommandOption lookupOption(String name) {
-	CommandOption commandOption = (CommandOption)longOptions.get(name);
-	if (commandOption == null)
-	    commandOption = (CommandOption)shortOptions.get(name);
+	CommandOption commandOption = (CommandOption)shortOptions.get(name);
+	if (commandOption != null)
+	    return commandOption;
+	for (Iterator i = longOptions.values().iterator(); i.hasNext(); ) {
+	    CommandOption option = (CommandOption)i.next();
+	    if (option.longName.startsWith(name)) {
+		if (commandOption != null)
+		    return null; // ambigious
+		commandOption = option;
+	    }
+	}
 	return commandOption;
     }
 
diff --git a/frysk-core/frysk/hpd/TestParameterizedCommand.java b/frysk-core/frysk/hpd/TestParameterizedCommand.java
index 186a175..fa26903 100644
--- a/frysk-core/frysk/hpd/TestParameterizedCommand.java
+++ b/frysk-core/frysk/hpd/TestParameterizedCommand.java
@@ -77,6 +77,13 @@ public class TestParameterizedCommand extends TestLib {
 		    assertNotNull("-arg's argument", argument);
 		}
 	    });
+	// make -a ambigious
+	command.add(new CommandOption("aRG", "long parameterized option",
+				      "ARG") {
+		void parse(String arg, Object options) {
+		    fail("should never specify -aRG");
+		}
+	    });
 	command.add(new CommandOption("opt", "long option") {
 		void parse(String arg, Object options) {
 		    parsedOption = true;
@@ -176,6 +183,15 @@ public class TestParameterizedCommand extends TestLib {
 	checkInvalid("parser -unknown");
     }
 
+    public void testShortAmbigiousOption() {
+	checkInvalid("parser -a");
+    }
+    public void testShortUnambigiousOption() {
+	check("parser arg -o", "arg",
+	      new String[] { "arg" },
+	      true, null);
+    }
+
     public void testHelp() {
 	parse("parser -help");
 	assertFalse("interpreted", interpreted);


hooks/post-receive
--
frysk system monitor/debugger


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]