Created
October 15, 2014 08:13
-
-
Save lucacesari/ef824b02da4973b88874 to your computer and use it in GitHub Desktop.
Get Eclipse application arguments
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 content is released under the MIT License (http://opensource.org/licenses/MIT). | |
* Copyright (c) 2014 Luca Cesari <[email protected]> | |
*/ | |
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