Skip to content

Instantly share code, notes, and snippets.

@lucacesari
Created October 15, 2014 08:13
Show Gist options
  • Save lucacesari/ef824b02da4973b88874 to your computer and use it in GitHub Desktop.
Save lucacesari/ef824b02da4973b88874 to your computer and use it in GitHub Desktop.
Get Eclipse application arguments
/*
* This content is released under the MIT License (http://opensource.org/licenses/MIT).
* Copyright (c) 2014 Luca Cesari <luc@cesari.me>
*/
package lucacesari.gists;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.PlatformUI;
public class CliUtils {
private CliUtils() {}
public static Map<String, String> getApplicationArguments() {
final String[] args = Platform.getApplicationArgs();
if (args.length == 0) {
return Collections.emptyMap();
} else {
final Map<String,String> map = new HashMap<String, String>();
for (int i = 0; i < args.length; i += 1) {
if (args[i].charAt(0) == '-') {
final String option = args[i].substring(1);
String value = "";
if (i + 1 < args.length && args[i + 1].charAt(0) != '-') {
i += 1;
value = args[i];
}
map.put(option, value);
}
}
return map;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment