# HG changeset patch # User Artem Tikhomirov # Date 1316258812 -7200 # Node ID 45dc79e545f5c8e5cef0be85e0b2b540d51c7d12 # Parent aac0c3fab6cee68097004e11f5753e52670ca235 Recognize flag options (options with no arguments) in command line sample apps diff -r aac0c3fab6ce -r 45dc79e545f5 cmdline/org/tmatesoft/hg/console/Bundle.java --- a/cmdline/org/tmatesoft/hg/console/Bundle.java Sat Sep 17 12:24:50 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Bundle.java Sat Sep 17 13:26:52 2011 +0200 @@ -17,6 +17,7 @@ package org.tmatesoft.hg.console; import java.io.File; +import java.util.Collections; import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.repo.HgBundle; @@ -34,7 +35,7 @@ */ public class Bundle { public static void main(String[] args) throws Exception { - Options cmdLineOpts = Options.parse(args); + Options cmdLineOpts = Options.parse(args, Collections.emptySet()); final HgRepository hgRepo = cmdLineOpts.findRepository(); if (hgRepo.isInvalid()) { System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); diff -r aac0c3fab6ce -r 45dc79e545f5 cmdline/org/tmatesoft/hg/console/Cat.java --- a/cmdline/org/tmatesoft/hg/console/Cat.java Sat Sep 17 12:24:50 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Cat.java Sat Sep 17 13:26:52 2011 +0200 @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; +import java.util.Collections; import org.tmatesoft.hg.repo.HgDataFile; import org.tmatesoft.hg.repo.HgRepository; @@ -34,7 +35,7 @@ public class Cat { public static void main(String[] args) throws Exception { - Options cmdLineOpts = Options.parse(args); + Options cmdLineOpts = Options.parse(args, Collections.emptySet()); HgRepository hgRepo = cmdLineOpts.findRepository(); if (hgRepo.isInvalid()) { System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); diff -r aac0c3fab6ce -r 45dc79e545f5 cmdline/org/tmatesoft/hg/console/Clone.java --- a/cmdline/org/tmatesoft/hg/console/Clone.java Sat Sep 17 12:24:50 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Clone.java Sat Sep 17 13:26:52 2011 +0200 @@ -17,6 +17,7 @@ package org.tmatesoft.hg.console; import java.io.File; +import java.util.Collections; import java.util.List; import org.tmatesoft.hg.core.HgCloneCommand; @@ -33,7 +34,7 @@ // ran with args: svnkit c:\temp\hg\test-clone public static void main(String[] args) throws Exception { - Options cmdLineOpts = Options.parse(args); + Options cmdLineOpts = Options.parse(args, Collections.emptySet()); List noOptsArgs = cmdLineOpts.getList(""); if (noOptsArgs.isEmpty()) { System.err.println("Need at least one argument pointing to remote server to pull changes from"); diff -r aac0c3fab6ce -r 45dc79e545f5 cmdline/org/tmatesoft/hg/console/Incoming.java --- a/cmdline/org/tmatesoft/hg/console/Incoming.java Sat Sep 17 12:24:50 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Incoming.java Sat Sep 17 13:26:52 2011 +0200 @@ -46,7 +46,7 @@ new SequenceConstructor().test(); return; } - Options cmdLineOpts = Options.parse(args); + Options cmdLineOpts = Options.parse(args, Collections.emptySet()); HgRepoFacade hgRepo = new HgRepoFacade(); if (!hgRepo.init(cmdLineOpts.findRepository())) { System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation()); diff -r aac0c3fab6ce -r 45dc79e545f5 cmdline/org/tmatesoft/hg/console/Log.java --- a/cmdline/org/tmatesoft/hg/console/Log.java Sat Sep 17 12:24:50 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Log.java Sat Sep 17 13:26:52 2011 +0200 @@ -16,6 +16,8 @@ */ package org.tmatesoft.hg.console; +import static org.tmatesoft.hg.console.Options.asSet; + import java.util.List; import org.tmatesoft.hg.core.HgFileRevision; @@ -35,7 +37,7 @@ // -agentlib:hprof=heap=sites,depth=10,etc might be handy to debug speed/memory issues public static void main(String[] args) throws Exception { - Options cmdLineOpts = Options.parse(args); + Options cmdLineOpts = Options.parse(args, asSet("--debug", "-v", "--verbose", "--hg4j-order-direct")); HgRepository hgRepo = cmdLineOpts.findRepository(); if (hgRepo.isInvalid()) { System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); @@ -49,7 +51,7 @@ final Dump dump = new Dump(hgRepo); dump.complete(cmdLineOpts.getBoolean("--debug")); dump.verbose(cmdLineOpts.getBoolean("-v", "--verbose")); - final boolean reverseOrder = true; + final boolean reverseOrder = !cmdLineOpts.getBoolean("--hg4j-order-direct"); dump.reversed(reverseOrder); HgLogCommand cmd = new HgLogCommand(hgRepo); for (String u : cmdLineOpts.getList("-u", "--user")) { diff -r aac0c3fab6ce -r 45dc79e545f5 cmdline/org/tmatesoft/hg/console/Main.java --- a/cmdline/org/tmatesoft/hg/console/Main.java Sat Sep 17 12:24:50 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Main.java Sat Sep 17 13:26:52 2011 +0200 @@ -74,7 +74,7 @@ private HgRepository hgRepo; public Main(String[] args) throws Exception { - cmdLineOpts = Options.parse(args); + cmdLineOpts = Options.parse(args, Collections.emptySet()); hgRepo = cmdLineOpts.findRepository(); if (hgRepo.isInvalid()) { System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); diff -r aac0c3fab6ce -r 45dc79e545f5 cmdline/org/tmatesoft/hg/console/Manifest.java --- a/cmdline/org/tmatesoft/hg/console/Manifest.java Sat Sep 17 12:24:50 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Manifest.java Sat Sep 17 13:26:52 2011 +0200 @@ -16,6 +16,7 @@ */ package org.tmatesoft.hg.console; +import static org.tmatesoft.hg.console.Options.asSet; import static org.tmatesoft.hg.repo.HgRepository.TIP; import org.tmatesoft.hg.core.HgFileRevision; @@ -33,7 +34,7 @@ public class Manifest { public static void main(String[] args) throws Exception { - Options cmdLineOpts = Options.parse(args); + Options cmdLineOpts = Options.parse(args, asSet("--debug", "-v", "--verbose")); HgRepository hgRepo = cmdLineOpts.findRepository(); if (hgRepo.isInvalid()) { System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); diff -r aac0c3fab6ce -r 45dc79e545f5 cmdline/org/tmatesoft/hg/console/Options.java --- a/cmdline/org/tmatesoft/hg/console/Options.java Sat Sep 17 12:24:50 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Options.java Sat Sep 17 13:26:52 2011 +0200 @@ -16,10 +16,13 @@ */ package org.tmatesoft.hg.console; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.repo.HgRepository; @@ -86,7 +89,7 @@ } - public static Options parse(String[] commandLineArgs) { + public static Options parse(String[] commandLineArgs, Set flagOptions) { Options rv = new Options(); List values = new LinkedList(); rv.opt2values.put("", values); // values with no options @@ -96,9 +99,14 @@ if (arg.length() == 1) { throw new IllegalArgumentException("Bad option: -"); } - values = rv.opt2values.get(arg); - if (values == null) { - rv.opt2values.put(arg, values = new LinkedList()); + if (flagOptions.contains(arg)) { + rv.opt2values.put(arg, Collections.emptyList()); + values = rv.opt2values.get(""); + } else { + values = rv.opt2values.get(arg); + if (values == null) { + rv.opt2values.put(arg, values = new LinkedList()); + } } // next value, if any, gets into the values list for arg option. } else { @@ -108,4 +116,12 @@ } return rv; } + + public static Set asSet(String... ss) { + TreeSet rv = new TreeSet(); + for (String s : ss) { + rv.add(s); + } + return rv; + } } \ No newline at end of file diff -r aac0c3fab6ce -r 45dc79e545f5 cmdline/org/tmatesoft/hg/console/Outgoing.java --- a/cmdline/org/tmatesoft/hg/console/Outgoing.java Sat Sep 17 12:24:50 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Outgoing.java Sat Sep 17 13:26:52 2011 +0200 @@ -17,6 +17,7 @@ package org.tmatesoft.hg.console; import java.util.Collection; +import java.util.Collections; import java.util.List; import org.tmatesoft.hg.core.HgOutgoingCommand; @@ -35,7 +36,7 @@ public class Outgoing { public static void main(String[] args) throws Exception { - Options cmdLineOpts = Options.parse(args); + Options cmdLineOpts = Options.parse(args, Collections.emptySet()); HgRepoFacade hgRepo = new HgRepoFacade(); if (!hgRepo.init(cmdLineOpts.findRepository())) { System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation()); diff -r aac0c3fab6ce -r 45dc79e545f5 cmdline/org/tmatesoft/hg/console/Status.java --- a/cmdline/org/tmatesoft/hg/console/Status.java Sat Sep 17 12:24:50 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Status.java Sat Sep 17 13:26:52 2011 +0200 @@ -16,6 +16,7 @@ */ package org.tmatesoft.hg.console; +import static org.tmatesoft.hg.console.Options.asSet; import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; import java.util.ArrayList; @@ -25,6 +26,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import org.tmatesoft.hg.core.HgRepoFacade; import org.tmatesoft.hg.core.HgStatus; @@ -40,7 +42,10 @@ public class Status { public static void main(String[] args) throws Exception { - Options cmdLineOpts = Options.parse(args); + final Set flagOpts = asSet("-A", "-all", "-m", "--modified", "-a", "--added", "-r", "--removed", + "--d", "--deleted", "-u", "--unknown", "-c", "--clean", "-i", "--ignored", + "-n", "--no-status", "-C", "--copies"); + Options cmdLineOpts = Options.parse(args, flagOpts); HgRepoFacade hgRepo = new HgRepoFacade(); if (!hgRepo.init(cmdLineOpts.findRepository())) { System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation()); diff -r aac0c3fab6ce -r 45dc79e545f5 cmdline/org/tmatesoft/hg/console/Tags.java --- a/cmdline/org/tmatesoft/hg/console/Tags.java Sat Sep 17 12:24:50 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Tags.java Sat Sep 17 13:26:52 2011 +0200 @@ -16,6 +16,7 @@ */ package org.tmatesoft.hg.console; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Map; @@ -34,7 +35,7 @@ public class Tags { public static void main(String[] args) throws Exception { - Options cmdLineOpts = Options.parse(args); + Options cmdLineOpts = Options.parse(args, Collections.emptySet()); HgRepository hgRepo = cmdLineOpts.findRepository(); if (hgRepo.isInvalid()) { System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation());