# Re: [JGIT PATCH 17/28] Support automatic command line parsing for TextBuiltin subclasses

2 messages from 2008-07-18 to 2008-07-18. Participants: Florian Köberle, Shawn O. Pearce.
Thread: https://gitlist.dev/t/14529

## Florian Köberle, 2008-07-18 19:01

Subject: Re: [JGIT PATCH 17/28] Support automatic command line parsing for TextBuiltin subclasses
Message-ID: <4880E880.1010403@web.de>
URL: https://gitlist.dev/e/4880E880.1010403%40web.de

```
Hi Shawn

to use args4j was really a great idea. I had a patch, implementing
something similar to args4j in my repository, but using a library is
always better. *thumb up*


I had a short look at the files and noticed that the inner "if (help) {"
is unnecessary:

+		if (help) {
+			System.err.print("jgit ");
+			System.err.print(commandName);
+			clp.printSingleLineUsage(System.err);
+			System.err.println();
+
+			if (help) {
+				System.err.println();
+				clp.printUsage(System.err);
+				System.err.println();
+			}
+			System.exit(1);
+		}

Also a cool function which you may want to use is:

public <U> Class<? extends U> asSubclass(Class<U> clazz)

With that method of Class<?> you can do the cast before you actually
create the object.
You could for example make use of them in SubcommandHandler:
l. 124			cmd = (TextBuiltin) cons.newInstance();

Best regards,
Florian Köberle

```

## Shawn O. Pearce, 2008-07-18 20:38

Subject: Re: [JGIT PATCH 17/28] Support automatic command line parsing for TextBuiltin subclasses
Message-ID: <20080718203834.GA27528@spearce.org>
URL: https://gitlist.dev/e/20080718203834.GA27528%40spearce.org
In-Reply-To: <4880E880.1010403@web.de>

```
Florian KKKberle <FloriansKarten@web.de> wrote:
> I had a short look at the files and noticed that the inner "if (help) {"
> is unnecessary:
>
> +		if (help) {
> +			System.err.print("jgit ");
> +			System.err.print(commandName);
> +			clp.printSingleLineUsage(System.err);
> +			System.err.println();
> +
> +			if (help) {

Gaaah.  Good catch, thanks.  I copied and pasted that block from the
global option parser to the per-command parser, and then refactored
it a little and missed removing this unnecessary inner if test.
I'll fix with a rebase.

-- 
Shawn.

```
