package thirtytwo.degrees.halfpipe.example.cli;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.lang.StringUtils;
import org.springframework.shell.core.CommandMarker;
import org.springframework.shell.core.annotation.*;
import org.springframework.stereotype.Component;
import thirtytwo.degrees.halfpipe.example.resources.Sayer;

import javax.inject.Inject;

/**
 * User: spencergibb
 * Date: 9/26/12
 * Time: 10:07 PM
 */
@Component
public class HelloCommand implements CommandMarker {

    @Inject
    Sayer sayer;

    @CliAvailabilityIndicator({"hello"})
    public boolean isCommandAvailable() {
        return true;
    }

    @CliCommand(value = "hello", help = "Say hello to the shell")
    public String hello(
            @CliOption(key = "message", mandatory = true, help = "The hello world message")
            String message,

            @CliOption(key = "more", mandatory = false,
                    help = "Have some more to say while saying hello",
                    specifiedDefaultValue="")
            String more)
    {
        StringBuilder hello = new StringBuilder(sayer.hello());
        hello.append(" with this message, "+message);
        if (!StringUtils.isBlank(more)) {
            hello.append(" "+more);
        }
        //System.out.println("\n\n\n\n"+hello+"\n\n\n\n");
        return hello.toString();
    }
}

@@ -1089,16 +1089,131 @@
 ing more
+,%0A%0A            @CliOption(key = %7B%22%22, %22config%22%7D, mandatory = false, help = %22config file%22)%0A            String config 
 )%0A    %7B%0A

add optional config file to hellocommand