PropertyCLI.java

package org.docascode.office;

import org.docascode.utils.Utils;
import picocli.CommandLine;

import java.io.File;
import java.util.HashMap;

@CommandLine.Command(name = "property")
public class PropertyCLI implements Runnable {
    @CommandLine.Option(names = {"--file","-f"} , description = "The file to act on")
    private File file;

    @CommandLine.Option(names = "--get", description = "Get the value for a given key")
    private boolean get;

    @CommandLine.Option(names = {"--list","-l"}, description = "List all properties")
    private boolean list;

    @CommandLine.Parameters(index = "0", arity = "0..1", description = "The key to get or set.")
    private String key;

    @CommandLine.Parameters(index = "1", arity = "0..1", description = "For writing options: the value to set")
    private String value;

    @Override
    public void run() {
        if (list){
            PropertyCtrl propertyCtrl = new PropertyCtrl();
            HashMap<String,String> map = propertyCtrl.getProperties(file);
            String value;
            for (HashMap.Entry<String, String> entry : map.entrySet()) {
                Utils.info(entry.getKey()+"="+entry.getValue());
            }
        }
    }
}