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

     1  package clear
     2  
     3  import (
     4  	"github.com/Sirupsen/logrus"
     5  	"github.com/daticahealth/cli/models"
     6  	"github.com/jault3/mow.cli"
     7  )
     8  
     9  // Cmd is the contract between the user and the CLI. This specifies the command
    10  // name, arguments, and required/optional arguments and flags for the command.
    11  var Cmd = models.Command{
    12  	Name:      "clear",
    13  	ShortHelp: "Clear out information in the global settings file to fix a misconfigured CLI.",
    14  	LongHelp: "<code>clear</code> allows you to manage your global settings file in case your CLI becomes misconfigured. " +
    15  		"The global settings file is stored in your home directory at <code>~/.datica</code>. " +
    16  		"You can clear out all settings or pick and choose which ones need to be removed. " +
    17  		"After running the <code>clear</code> command, any other CLI command will reset the removed settings to their appropriate values. Here are some sample commands\n\n" +
    18  		"<pre>\ndatica clear --all\n" +
    19  		"datica clear --environments # removes your locally cached environment(s) configuration data\n" +
    20  		"datica clear --session --private-key # removes all session and private key authentication information\n</pre>",
    21  	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
    22  		return func(cmd *cli.Cmd) {
    23  			privateKey := cmd.BoolOpt("private-key", false, "Clear out the saved private key information")
    24  			session := cmd.BoolOpt("session", false, "Clear out all session information")
    25  			envs := cmd.BoolOpt("environments", false, "Clear out all your environment data")
    26  			pods := cmd.BoolOpt("pods", false, "Clear out all saved pods")
    27  			all := cmd.BoolOpt("all", false, "Clear out all settings")
    28  			cmd.Action = func() {
    29  				if *all {
    30  					*privateKey = true
    31  					*session = true
    32  					*envs = true
    33  					*pods = true
    34  				}
    35  				err := CmdClear(*privateKey, *session, *envs, *pods, settings)
    36  				if err != nil {
    37  					logrus.Fatal(err.Error())
    38  				}
    39  			}
    40  			cmd.Spec = "[--private-key] [--session] [--environments] [--pods] [--all]"
    41  		}
    42  	},
    43  }