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

Add support for -p and -u command line arguments #2

Merged
merged 3 commits into from
Mar 18, 2016
Merged
Show file tree
Hide file tree
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
Binary file modified dist/perforce-patcher.jar
Binary file not shown.
38 changes: 26 additions & 12 deletions src/main/java/org/buddha/perforce/patch/fx/FXMLController.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,32 @@ public void initialize(URL url, ResourceBundle rb) {
changeListField.setDisable(true);
workspaceField.setDisable(true);
generatePatchButton.setDisable(true);
p4PortField.setText(prefs.getP4port());
userNameField.setText(prefs.getUsername());
passwordField.setText(prefs.getPassword());
workspaceField.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
if(changelists != null && changelists.containsKey(newValue)) {
changeListField.getItems().setAll(changelists.get(newValue));
changeListField.getSelectionModel().selectFirst();
}
}
});
if (!MainApp.options.isEmpty()) {
try {
p4PortField.setText(MainApp.options.get("-p").toString());
} catch (Exception e) {
console.appendText("Unable to get port from command line.\n");
}
try {
userNameField.setText(MainApp.options.get("-u").toString());
} catch (Exception e) {
console.appendText("Unable to get user from command line.\n");
}

} else {
p4PortField.setText(prefs.getP4port());
userNameField.setText(prefs.getUsername());
passwordField.setText(prefs.getPassword());
}
workspaceField.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
if(changelists != null && changelists.containsKey(newValue)) {
changeListField.getItems().setAll(changelists.get(newValue));
changeListField.getSelectionModel().selectFirst();
}
}
});
}

private ChangeListener<String> getLoggerListener() {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/buddha/perforce/patch/fx/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.HashMap;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.event.EventHandler;
Expand All @@ -15,8 +16,11 @@
import javax.swing.ImageIcon;
import org.buddha.perforce.patch.util.P4Manager;
import org.buddha.perforce.patch.Config;
import org.buddha.perforce.patch.util.StringUtils;

public class MainApp extends Application {

static HashMap options = new HashMap();

@Override
public void start(Stage stage) throws Exception {
Expand Down Expand Up @@ -62,6 +66,7 @@ public void handle(WindowEvent we) {
* @param args the command line arguments
*/
public static void main(String[] args) {
options = StringUtils.parseArgs(args);
launch(args);
}

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/org/buddha/perforce/patch/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.List;
import org.buddha.perforce.patch.Item;

Expand Down Expand Up @@ -37,4 +38,30 @@ public static String exceptionToString(Exception ex) {
ex.printStackTrace(new PrintWriter(writer));
return writer.toString();
}

public static HashMap parseArgs(String[] args) {
HashMap results = new HashMap();
for (int i = 0; i <= args.length - 1; i++) {
String value = "";
if (args[i].indexOf("-") == 0) {
if (args[i].length() == 2) {
try {
value = args[i+1];
} catch (Exception e) {
System.out.println("Unable to get value after flag '" + args[i] + "'" );
}
} else if (args[i].length() > 2) {
value = args[i].substring(2);
} else if (args[i].length() == 1) {
System.out.println("Invalid flag");
}
if (args[i].charAt(1) == 'p') {
results.put("-p", value);
} else if (args[i].charAt(1) == 'u') {
results.put("-u", value);
}
}
}
return results;
}
}