public inbox for frysk-cvs@sourceware.org help / color / mirror / Atom feed
From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Allow abbreviated long options. Date: Wed, 14 Nov 2007 18:04:00 -0000 [thread overview] Message-ID: <20071114180448.9614.qmail@sourceware.org> (raw) 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
reply other threads:[~2007-11-14 18:04 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20071114180448.9614.qmail@sourceware.org \ --to=cagney@sourceware.org \ --cc=frysk-cvs@sourceware.org \ --cc=frysk@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).