package ee.shy.cli.command;

import ee.shy.cli.Command;
import ee.shy.cli.HelptextBuilder;
import ee.shy.core.Repository;
import org.apache.commons.lang3.ArrayUtils;

import java.io.IOException;

/**
 * A command to checkout.
 */
public class CheckoutCommand implements Command {
    @Override
    public void execute(String[] args) throws IOException {
        Repository repository = Repository.newExisting();
        repository.checkout(args[0]);
    }

    @Override
    public String getHelp() {
        return new HelptextBuilder()
                .addWithArgs("<hash>", "Check out given commit")
                .addWithArgs("<branch>", "Check out given branch")
                .addDescription("Checks out commits and branches.")
                .create();
    }

    @Override
    public String getHelpBrief() {
        return "Check out commits and branches";
    }

    @Override
    public String[] getCompletion(String[] args) throws IOException {
        Repository repository = Repository.newExisting();
        return ArrayUtils.addAll(
                    repository.getBranches().keySet().toArray(new String[0]),
                    repository.getTags().keySet().toArray(new String[0])
                );
    }
}
@@ -339,32 +339,68 @@
 s IOException %7B%0A
+        if (args.length %3E= 1) %7B%0A    
         Reposito
@@ -441,32 +441,36 @@
 ting();%0A        
+    
 repository.check
@@ -483,16 +483,114 @@
 gs%5B0%5D);%0A
+        %7D else%0A            System.err.println(%22Not enough parameters. See 'shy help checkout'.%22);%0A
     %7D%0A%0A 

Validate args length in CheckoutCommand