function readArgs(args){
    let result = {
        switches: new Set(),// Single letter toggles
        params: new Map(),// Named params/toggles
        args: [],
        get: function(...keys){
            let value;
            for (let k of keys) {
                let newValue = result.params.get(k);
                if(newValue!==undefined) {
                    value = newValue;
                } else if (result.switches.has(k)){
                    value = true;
                }
            }
            return value;
        }
    };
    for(let arg of args){
        if(arg[0]==='-'){
            if(arg[1]==='-'){
                // Full name
                let argName  = arg.slice(2);
                let argValue = true;
                let eqIndex = argName.indexOf("=");
                if(eqIndex>0){
                    argValue = argName.slice(eqIndex+1);
                    try{
                        argValue = JSON.parse(argValue);
                    }catch(ex){}
                    argName = argName.slice(0,eqIndex);
                }
                result.params.set(argName, argValue);
            }else{
                // Switches
                let switches = arg.slice(1);
                for(let l of switches){result.switches.add(l);}
            }
        }else{
            result.args.push(arg);
        }
    }
    return result;
}

module.exports = readArgs;