Update.java

package org.docascode.cli;

import org.docascode.api.UpdateCommand;
import org.docascode.api.core.errors.DocAsCodeException;
import picocli.CommandLine;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.docascode.api.DocAsCode;

@CommandLine.Command(name = "update",
    description="Create or update Custom properties of OpenXML files.")
public class Update extends Command implements Runnable {
    @CommandLine.Option(names = {"--file","-f"} , arity = "1", description = "The file to act on")
    private File file;

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

    @CommandLine.Option(names = {"-p"}, description = "The properties to set/update")
    private Map<String, String> properties = new HashMap<>();

    @Override
    public void run() {
        UpdateCommand update = DocAsCode.update()
                .setFile(file);
        if (list){
            update.setAction(UpdateCommand.Action.LIST);
        } else {
            update.setProperties(properties)
                .setAction(UpdateCommand.Action.ADD);
        }
        try {
            Map<String,String> updateList = update.call();
            for (HashMap.Entry<String,String> entry : updateList.entrySet()){
                success(String.format(
                    "%s: '%s'%n",
                    entry.getKey(),
                    entry.getValue()));
            }
        } catch (DocAsCodeException e) {
            error(e);
        }
    }
}