forked from redhat-developer/odo
/
logout.go
64 lines (53 loc) · 1.73 KB
/
logout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package logout
import (
"fmt"
"github.com/openshift/odo/pkg/odo/genericclioptions"
odoutil "github.com/openshift/odo/pkg/odo/util"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"os"
)
// RecommendedCommandName is the recommended command name
const RecommendedCommandName = "logout"
var example = templates.Examples(` # Logout
%[1]s
`)
// LogoutOptions encapsulates the options for the odo logout command
type LogoutOptions struct {
*genericclioptions.Context
}
// NewLogoutOptions creates a new LogoutOptions instance
func NewLogoutOptions() *LogoutOptions {
return &LogoutOptions{}
}
// Complete completes LogoutOptions after they've been created
func (o *LogoutOptions) Complete(name string, cmd *cobra.Command, args []string) (err error) {
o.Context = genericclioptions.NewContext(cmd)
return
}
// Validate validates the LogoutOptions based on completed values
func (o *LogoutOptions) Validate() (err error) {
return
}
// Run contains the logic for the odo logout command
func (o *LogoutOptions) Run() (err error) {
return o.Client.RunLogout(os.Stdout)
}
// NewCmdLogout implements the logout odo command
func NewCmdLogout(name, fullName string) *cobra.Command {
o := NewLogoutOptions()
logoutCmd := &cobra.Command{
Use: name,
Short: "Log out of the current OpenShift session",
Long: "Log out of the current OpenShift session",
Example: fmt.Sprintf(example, fullName),
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
}
// Add a defined annotation in order to appear in the help menu
logoutCmd.Annotations = map[string]string{"command": "utility"}
logoutCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
return logoutCmd
}