github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/commands/status/contract.go (about)

     1  package status
     2  
     3  import (
     4  	"github.com/Sirupsen/logrus"
     5  	"github.com/daticahealth/cli/commands/environments"
     6  	"github.com/daticahealth/cli/commands/services"
     7  	"github.com/daticahealth/cli/config"
     8  	"github.com/daticahealth/cli/lib/auth"
     9  	"github.com/daticahealth/cli/lib/jobs"
    10  	"github.com/daticahealth/cli/lib/prompts"
    11  	"github.com/daticahealth/cli/models"
    12  	"github.com/jault3/mow.cli"
    13  )
    14  
    15  // Cmd is the contract between the user and the CLI. This specifies the command
    16  // name, arguments, and required/optional arguments and flags for the command.
    17  var Cmd = models.Command{
    18  	Name:      "status",
    19  	ShortHelp: "Get quick readout of the current status of an environment and all of its services",
    20  	LongHelp: "<code>status</code> will give a quick readout of your environment's health. " +
    21  		"This includes your environment name, environment ID, and for each service the name, size, build status, deploy status, and service ID. " +
    22  		"Here is a sample command\n\n" +
    23  		"<pre>\ndatica -E \"<your_env_name>\" status\ndatica -E \"<your_env_name>\" status --historical\n</pre>",
    24  	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
    25  		return func(cmd *cli.Cmd) {
    26  			historical := cmd.BoolOpt("historical", false, "If this option is specified, a complete history of jobs will be reported")
    27  			cmd.Action = func() {
    28  				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
    29  					logrus.Fatal(err.Error())
    30  				}
    31  				if err := config.CheckRequiredAssociation(settings); err != nil {
    32  					logrus.Fatal(err.Error())
    33  				}
    34  				err := CmdStatus(settings.EnvironmentID, New(settings, jobs.New(settings)), environments.New(settings), services.New(settings), *historical)
    35  				if err != nil {
    36  					logrus.Fatal(err.Error())
    37  				}
    38  			}
    39  			cmd.Spec = "[--historical]"
    40  		}
    41  	},
    42  }
    43  
    44  // IStatus
    45  type IStatus interface {
    46  	Status(env *models.Environment, services *[]models.Service, historical bool) error
    47  }
    48  
    49  // SStatus is a concrete implementation of IStatus
    50  type SStatus struct {
    51  	Settings *models.Settings
    52  	Jobs     jobs.IJobs
    53  }
    54  
    55  // New returns an instance of IStatus
    56  func New(settings *models.Settings, ij jobs.IJobs) IStatus {
    57  	return &SStatus{
    58  		Settings: settings,
    59  		Jobs:     ij,
    60  	}
    61  }