github.com/chenbh/concourse/v6@v6.4.2/fly/commands/status.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/chenbh/concourse/v6/fly/commands/internal/displayhelpers"
     7  	"github.com/chenbh/concourse/v6/fly/rc"
     8  )
     9  
    10  type StatusCommand struct{}
    11  
    12  func (c *StatusCommand) Execute([]string) error {
    13  	target, err := rc.LoadTarget(Fly.Target, Fly.Verbose)
    14  	if err != nil {
    15  		return err
    16  	}
    17  
    18  	tToken := target.Token()
    19  
    20  	if tToken == nil || tToken.Value == "" {
    21  		displayhelpers.Failf("logged out")
    22  		return nil
    23  	}
    24  
    25  	_, err = target.Client().UserInfo()
    26  	if err != nil {
    27  		displayhelpers.FailWithErrorf("please login again.\n\ntoken validation failed with error", err)
    28  		return nil
    29  	}
    30  
    31  	fmt.Println("logged in successfully")
    32  	return nil
    33  }