All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kicksolutions.CliArgs Maven / Gradle / Ivy

The newest version!
package com.kicksolutions;

import java.util.HashMap;

/**
 */
public class CliArgs {

    private String[] args = null;

    private HashMap parsedCliArguments = new HashMap();
    
    public CliArgs(String[] args){
        parse(args);
    }

    public void parse(String[] arguments){
        this.args = arguments;
        parsedCliArguments.clear();
            
        for(int i=0; i < args.length; i++) {
            if(args[i].startsWith("-") ){
            	parsedCliArguments.put(args[i], args[i+1]);
            }
        }
    }

    public String[] args() {
        return args;
    }

    public String arg(int index){
        return args[index];
    }

    public boolean isArgumentPresent(String argument) {
        return parsedCliArguments.containsKey(argument);
    }

    public String getArgumentValue(String argument, String defaultValue) {
    	if(!isArgumentPresent(argument)){
    		return defaultValue;
    	}
    	else{
    		return parsedCliArguments.get(argument);
    	}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy