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

     1  package logout
     2  
     3  import (
     4  	"github.com/Sirupsen/logrus"
     5  	"github.com/daticahealth/cli/lib/auth"
     6  	"github.com/daticahealth/cli/lib/prompts"
     7  	"github.com/daticahealth/cli/models"
     8  	"github.com/jault3/mow.cli"
     9  )
    10  
    11  // Cmd is the contract between the user and the CLI. This specifies the command
    12  // name, arguments, and required/optional arguments and flags for the command.
    13  var Cmd = models.Command{
    14  	Name:      "logout",
    15  	ShortHelp: "Clear the stored user information from your local machine",
    16  	LongHelp: "When using the CLI, your email and password are <b>never</b> stored in any file on your filesystem. " +
    17  		"However, in order to not type in your email and password each and every command, a session token is stored in the CLI's configuration file and used until it expires. " +
    18  		"<code>logout</code> removes this session token from the configuration file. Here is a sample command\n\n" +
    19  		"<pre>\ndatica logout\n</pre>",
    20  	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
    21  		return func(cmd *cli.Cmd) {
    22  			cmd.Action = func() {
    23  				err := CmdLogout(New(settings), auth.New(settings, prompts.New()))
    24  				if err != nil {
    25  					logrus.Fatal(err.Error())
    26  				}
    27  			}
    28  		}
    29  	},
    30  }
    31  
    32  // ILogout
    33  type ILogout interface {
    34  	Clear() error
    35  }
    36  
    37  // SLogout is a concrete implementation of ILogout
    38  type SLogout struct {
    39  	Settings *models.Settings
    40  }
    41  
    42  // New returns an instance of ILogout
    43  func New(settings *models.Settings) ILogout {
    44  	return &SLogout{
    45  		Settings: settings,
    46  	}
    47  }