Remove System.out.println from RevWalkFilterTest
[egit/chris.git] / org.spearce.jgit.pgm / src / org / spearce / jgit / pgm / opt / SubcommandHandler.java
blob86004bb1d53899cb946cfd196b8efd6500092976
1 /*
2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
21 * written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org.spearce.jgit.pgm.opt;
40 import java.text.MessageFormat;
42 import org.kohsuke.args4j.CmdLineException;
43 import org.kohsuke.args4j.CmdLineParser;
44 import org.kohsuke.args4j.OptionDef;
45 import org.kohsuke.args4j.spi.OptionHandler;
46 import org.kohsuke.args4j.spi.Parameters;
47 import org.kohsuke.args4j.spi.Setter;
48 import org.spearce.jgit.pgm.CommandCatalog;
49 import org.spearce.jgit.pgm.CommandRef;
50 import org.spearce.jgit.pgm.TextBuiltin;
52 /**
53 * Custom Argument handler for jgit command selection.
54 * <p>
55 * Translates a single argument string to a {@link TextBuiltin} instance which
56 * we can execute at runtime with the remaining arguments of the parser.
58 public class SubcommandHandler extends OptionHandler<TextBuiltin> {
59 /**
60 * Create a new handler for the command name.
61 * <p>
62 * This constructor is used only by args4j.
64 * @param parser
65 * @param option
66 * @param setter
68 public SubcommandHandler(final CmdLineParser parser,
69 final OptionDef option, final Setter<? super TextBuiltin> setter) {
70 super(parser, option, setter);
73 @Override
74 public int parseArguments(final Parameters params) throws CmdLineException {
75 final String name = params.getParameter(0);
76 final CommandRef cr = CommandCatalog.get(name);
77 if (cr == null)
78 throw new CmdLineException(MessageFormat.format(
79 "{0} is not a jgit command", name));
81 // Force option parsing to stop. Everything after us should
82 // be arguments known only to this command and must not be
83 // recognized by the current parser.
85 owner.stopOptionParsing();
86 setter.addValue(cr.create());
87 return 1;
90 @Override
91 public String getDefaultMetaVariable() {
92 return "command";