This repository has been archived by the owner on Oct 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSAFE-2249 - Replace CLI flag parsing library JSAP with JCommander
Changed junit test code to reflect this added unit test cases for ogcli and objectfilecli
- Loading branch information
1 parent
3bc4993
commit 5308537
Showing
9 changed files
with
487 additions
and
76 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
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
82 changes: 82 additions & 0 deletions
82
og-configuration/src/main/java/com/cleversafe/og/cli/GetOpt.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,82 @@ | ||
/* | ||
* Copyright (C) 2005-2016 Cleversafe, Inc. All rights reserved. | ||
* | ||
* Contact Information: Cleversafe, Inc. 222 South Riverside Plaza Suite 1700 Chicago, IL 60606, USA | ||
* | ||
* licensing@cleversafe.com | ||
*/ | ||
|
||
package com.cleversafe.og.cli; | ||
|
||
import com.beust.jcommander.JCommander; | ||
import com.beust.jcommander.Parameter; | ||
|
||
|
||
public class GetOpt { | ||
@Parameter(names = {"--version", "-v"}, description = "Prints the og version and exits") | ||
private boolean version = false; | ||
|
||
@Parameter(names = {"--help", "-h"}, description = "Prints this help and exits") | ||
private boolean help; | ||
|
||
private boolean error; | ||
|
||
private String errorMsg = ""; | ||
|
||
private JCommander jc; | ||
|
||
public Boolean getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(Boolean version) { | ||
this.version = version; | ||
} | ||
|
||
public Boolean getHelp() { | ||
return help; | ||
} | ||
|
||
public void setHelp(Boolean help) { | ||
this.help = help; | ||
} | ||
|
||
public boolean isError() { | ||
return error; | ||
} | ||
|
||
public void setError(boolean error) { | ||
this.error = error; | ||
} | ||
|
||
public String getErrorMsg() { | ||
return errorMsg; | ||
} | ||
|
||
public void setErrorMsg(String errorMsg) { | ||
this.errorMsg = errorMsg; | ||
} | ||
|
||
|
||
|
||
public void processArguments (String progName, String args[]) { | ||
|
||
try { | ||
jc = new JCommander(this); | ||
jc.setProgramName(progName); | ||
jc.parse(args); | ||
} catch(RuntimeException re) { | ||
// record error in the state to match with the existing semantics | ||
error = true; | ||
errorMsg = re.getLocalizedMessage(); | ||
|
||
} | ||
|
||
} | ||
|
||
public void usage(StringBuilder sb) { | ||
jc.usage(sb); | ||
} | ||
|
||
|
||
} |
51 changes: 51 additions & 0 deletions
51
og-configuration/src/main/java/com/cleversafe/og/cli/OGGetOpt.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,51 @@ | ||
/* | ||
* Copyright (C) 2005-2016 Cleversafe, Inc. All rights reserved. | ||
* | ||
* Contact Information: Cleversafe, Inc. 222 South Riverside Plaza Suite 1700 Chicago, IL 60606, USA | ||
* | ||
* licensing@cleversafe.com | ||
*/ | ||
|
||
package com.cleversafe.og.cli; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.beust.jcommander.JCommander; | ||
import com.beust.jcommander.Parameter; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
|
||
class OGGetOpt extends GetOpt { | ||
|
||
@Parameter(description = "<og_config>", required = true) | ||
private List<String> arguments = new ArrayList<String>(); | ||
|
||
public OGGetOpt() { | ||
|
||
} | ||
|
||
public List<String> getArguments() { | ||
return arguments; | ||
} | ||
|
||
public void setArguments(List<String> arguments) { | ||
this.arguments = arguments; | ||
} | ||
|
||
public String getOGConfigFileName() { | ||
checkNotNull(arguments); | ||
return arguments.get(0); | ||
|
||
} | ||
|
||
public GetOpt getObject() { | ||
return new OGGetOpt(); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
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
Oops, something went wrong.