Skip to content

Commit

Permalink
cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Rode committed Jul 12, 2017
1 parent 59f1c8a commit d18c522
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/main/java/de/screenflow/frankenstein/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@ public class Configuration {

public SectionedProperties metadata = new SectionedProperties();

public static StringBuffer usage = new StringBuffer();

public static Configuration cliCreateConfiguration(String[] args) {
Configuration configuration = new Configuration(null);

int optionKeyIndex;
String optionValue;
Properties optionProperties;

usage.setLength(0);
usage.append("frankenstein");

optionKeyIndex = getOptionIndex(args, "visual");
configuration.setVisual(optionKeyIndex>=0);

Expand All @@ -87,6 +92,12 @@ public static Configuration cliCreateConfiguration(String[] args) {
optionProperties = getOptionProperties(args, optionKeyIndex);
cliConfigureSource(configuration, optionValue, optionProperties);

// todo ...

if (getOptionIndex(args, "?")>=0) {
return null;
}

return configuration;
}

Expand All @@ -108,8 +119,11 @@ private static void cliConfigureSource(Configuration configuration, String optio
}

private static int getOptionIndex(String[] args, String optionKey) {
usage.append(" -");
usage.append(optionKey);

for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("-" + optionKey + "=")) {
if (args[i].startsWith("-" + optionKey + "=") || args[i].equals("-" + optionKey)) {
return i;
}
}
Expand All @@ -118,6 +132,13 @@ private static int getOptionIndex(String[] args, String optionKey) {

private static String getOptionValue(String[] args, String optionKey, String defaultValue, int optionKeyIndex,
String... optionValues) {
usage.append("=");
for (String opt : optionValues) {
usage.append(opt);
usage.append('|');
}
usage.setLength(usage.length()-1);

if (optionKeyIndex < 0)
return defaultValue;

Expand Down Expand Up @@ -285,4 +306,8 @@ public void setVisual(boolean visual) {
this.visual = visual;
}

public static String getUsage() {
return usage.toString();
}

}
4 changes: 4 additions & 0 deletions src/main/java/de/screenflow/frankenstein/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public static void main(String[] args) {
System.out.println("Args: " + Arrays.toString(args));

Configuration c = Configuration.cliCreateConfiguration(args);
if (c == null) {
System.out.println(Configuration.getUsage());
System.exit(0);
}

if (args.length==0 || c.isVisual()) {

Expand Down

0 comments on commit d18c522

Please sign in to comment.