This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BZ 1073096] - Adding the check for any unrecognized arguments.
- Loading branch information
Showing
3 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...enterprise/server/server-control/src/main/java/org/rhq/server/control/RHQPosixParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* RHQ Management Platform | ||
* Copyright (C) 2005-2014 Red Hat, Inc. | ||
* All rights reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation version 2 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
*/ | ||
package org.rhq.server.control; | ||
|
||
import java.util.ListIterator; | ||
|
||
import org.apache.commons.cli.ParseException; | ||
import org.apache.commons.cli.PosixParser; | ||
|
||
/** | ||
* @author Jirka Kremser | ||
* | ||
* This parser class throws an exception if it finds some unknown option. | ||
* Option in the commons-cli terminology is the command line token starting with '-' or '--') | ||
* | ||
*/ | ||
public class RHQPosixParser extends PosixParser { | ||
private boolean ignoreUnrecognizedOption; | ||
|
||
public RHQPosixParser() { | ||
this(false); | ||
} | ||
|
||
public RHQPosixParser(final boolean ignoreUnrecognizedOption) { | ||
this.ignoreUnrecognizedOption = ignoreUnrecognizedOption; | ||
} | ||
|
||
@Override | ||
protected void processOption(final String arg, final ListIterator iter) throws ParseException { | ||
boolean hasOption = getOptions().hasOption(arg); | ||
|
||
if (hasOption || ignoreUnrecognizedOption) { | ||
throw new ParseException("Unknown option: " + arg); | ||
} | ||
super.processOption(arg, iter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters