package com.containersol.minimesos.main;

import java.io.PrintStream;

import com.beust.jcommander.Parameters;
import com.containersol.minimesos.cluster.ClusterRepository;
import com.containersol.minimesos.cluster.MesosCluster;
import com.containersol.minimesos.mesos.MesosClusterContainersFactory;

/**
 * Parameters for the 'state' command
 */
@Parameters(separators = "=", commandDescription = "Display the master's state.json file")
public class CommandState implements Command {

    public static final String CLINAME = "state";

    private PrintStream output = System.out; //NOSONAR

    private ClusterRepository repository = new ClusterRepository();

    public CommandState() { //NOSONAR
    }

    public CommandState(PrintStream ps) {
        this.output = ps;
    }

    @Override
    public void execute() {
        MesosCluster cluster = repository.loadCluster(new MesosClusterContainersFactory());
        if (cluster != null) {
            cluster.state(output);
        } else {
            output.println("Minimesos cluster is not running");
        }
    }

    @Override
    public boolean validateParameters() {
        return true;
    }

    @Override
    public String getName() {
        return CLINAME;
    }

}
