Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code refactoring of ClientOptions #876

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions common/client/src/main/java/zingg/common/client/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ClientOptions {

protected String[] commandLineArgs;

protected static Map<String, Option> optionMaster = new HashMap<String, Option>();
protected Map<String, Option> optionMaster = new HashMap<String, Option>();
/*
* String optionName;
//String alias;
Expand All @@ -52,7 +52,7 @@ public class ClientOptions {
boolean isExit;
boolean isMandatory;
*/
static { //This is the canonical list of Zingg options.
protected void loadOptions() { //This is the canonical list of Zingg options.
optionMaster.put(CONF, new Option(CONF, true, "JSON configuration with data input output locations and field definitions", false, true));
optionMaster.put(PHASE, new Option(PHASE, true, Util.join(ZinggOptions.getAllZinggOptions(), "|"), false, true, ZinggOptions.getAllZinggOptions()));
optionMaster.put(LICENSE, new Option(LICENSE, true, "location of license file", false, true));
Expand All @@ -76,22 +76,35 @@ public class ClientOptions {
}

protected Map<String, OptionWithVal> options = new HashMap<String, OptionWithVal> ();

public ClientOptions(){
loadOptions();
}

public ClientOptions(String... args) {
this();
this.commandLineArgs = args;
parse(Arrays.asList(args));
}

public ClientOptions(List<String> args) {
this();
this.commandLineArgs = args.toArray(new String[args.size()]);
parse(args);
}

public String[] getCommandLineArgs() {
return this.commandLineArgs;
}

public Map<String, Option> getOptionMaster(){
return optionMaster;
}


public void setOptionMaster(Map<String, Option> optionMaster) {
this.optionMaster = optionMaster;
}

/**
* Parse a list of Zingg command line options.
* <p>
Expand Down Expand Up @@ -250,20 +263,21 @@ public final static String getHelp() {
s.append("options\n");

int maxlo = 0;
for (Option o: optionMaster.values()){
ClientOptions co = new ClientOptions();
for (Option o: co.optionMaster.values()){
maxlo=Math.max(maxlo,o.optionName.length());
}

int maxld = 0;
for (Option o: optionMaster.values()){
for (Option o: co.optionMaster.values()){
maxld=Math.max(maxld,o.desc.length());
}

StringBuilder formatBuilder = new StringBuilder();
formatBuilder.append("\t").append("%-").append(maxlo + 5).append("s").append(": ").append("%-").append(maxld + 5).append("s").append("\n");
String format = formatBuilder.toString();

for (Option o: optionMaster.values()) {
for (Option o: co.optionMaster.values()) {
s.append(String.format(format,o.optionName, o.desc));
}
return s.toString();
Expand Down
Loading