github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/cf/commands/application/ssh_enabled.go (about)

     1  package application
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"code.cloudfoundry.org/cli/cf/commandregistry"
     7  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
     8  	"code.cloudfoundry.org/cli/cf/flags"
     9  	. "code.cloudfoundry.org/cli/cf/i18n"
    10  	"code.cloudfoundry.org/cli/cf/requirements"
    11  	"code.cloudfoundry.org/cli/cf/terminal"
    12  )
    13  
    14  type SSHEnabled struct {
    15  	ui     terminal.UI
    16  	config coreconfig.Reader
    17  	appReq requirements.ApplicationRequirement
    18  }
    19  
    20  func init() {
    21  	commandregistry.Register(&SSHEnabled{})
    22  }
    23  
    24  func (cmd *SSHEnabled) MetaData() commandregistry.CommandMetadata {
    25  	return commandregistry.CommandMetadata{
    26  		Name:        "ssh-enabled",
    27  		Description: T("Reports whether SSH is enabled on an application container instance"),
    28  		Usage: []string{
    29  			T("CF_NAME ssh-enabled APP_NAME"),
    30  		},
    31  	}
    32  }
    33  
    34  func (cmd *SSHEnabled) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
    35  	if len(fc.Args()) != 1 {
    36  		cmd.ui.Failed(T("Incorrect Usage. Requires APP_NAME as argument\n\n") + commandregistry.Commands.CommandUsage("ssh-enabled"))
    37  		return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1)
    38  	}
    39  
    40  	cmd.appReq = requirementsFactory.NewApplicationRequirement(fc.Args()[0])
    41  
    42  	reqs := []requirements.Requirement{
    43  		requirementsFactory.NewLoginRequirement(),
    44  		requirementsFactory.NewTargetedSpaceRequirement(),
    45  		cmd.appReq,
    46  	}
    47  
    48  	return reqs, nil
    49  }
    50  
    51  func (cmd *SSHEnabled) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command {
    52  	cmd.ui = deps.UI
    53  	cmd.config = deps.Config
    54  	return cmd
    55  }
    56  
    57  func (cmd *SSHEnabled) Execute(fc flags.FlagContext) error {
    58  	app := cmd.appReq.GetApplication()
    59  
    60  	if app.EnableSSH {
    61  		cmd.ui.Say(fmt.Sprintf(T("ssh support is enabled for")+" '%s'", app.Name))
    62  	} else {
    63  		cmd.ui.Say(fmt.Sprintf(T("ssh support is disabled for")+" '%s'", app.Name))
    64  	}
    65  
    66  	cmd.ui.Say("")
    67  	return nil
    68  }