Skip to content

Commit

Permalink
This adds the ability to silence oc on successful logins to prevent l…
Browse files Browse the repository at this point in the history
…arge clusters from being annoying.

For BZ 1542326
  • Loading branch information
Oats87 committed Feb 20, 2018
1 parent 908acaa commit 1ae2adf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions pkg/oc/cli/cmd/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func NewCmdLogin(fullName string, f *osclientcmd.Factory, reader io.Reader, out,
// Login is the only command that can negotiate a session token against the auth server using basic auth
cmds.Flags().StringVarP(&options.Username, "username", "u", "", "Username, will prompt if not provided")
cmds.Flags().StringVarP(&options.Password, "password", "p", "", "Password, will prompt if not provided")
cmds.Flags().BoolVarP(&options.Silent, "silent", "s", false, "If true, projects you have access to will not be listed on successful login.")

return cmds
}
Expand Down Expand Up @@ -152,6 +153,8 @@ func (o *LoginOptions) Complete(f *osclientcmd.Factory, cmd *cobra.Command, args
o.InsecureTLS = kcmdutil.GetFlagBool(cmd, "insecure-skip-tls-verify")
o.Token = kcmdutil.GetFlagString(cmd, "token")

o.Silent = kcmdutil.GetFlagBool(cmd, "silent")

o.DefaultNamespace, _, _ = f.DefaultNamespace()

o.PathOptions = config.NewPathOptions(cmd)
Expand Down
25 changes: 17 additions & 8 deletions pkg/oc/cli/cmd/login/loginoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type LoginOptions struct {

CommandName string
RequestTimeout time.Duration

// Silent login
Silent bool
}

// Gather all required information in a comprehensive order.
Expand Down Expand Up @@ -316,16 +319,17 @@ func (o *LoginOptions) gatherProjectInfo() error {
return err
}
o.Project = current.Name

fmt.Fprintf(o.Out, "You have access to the following projects and can switch between them with '%s project <projectname>':\n\n", o.CommandName)
for _, p := range projects.List() {
if o.Project == p {
fmt.Fprintf(o.Out, " * %s\n", p)
} else {
fmt.Fprintf(o.Out, " %s\n", p)
if (!o.silentLogin()) {
fmt.Fprintf(o.Out, "You have access to the following projects and can switch between them with '%s project <projectname>':\n\n", o.CommandName)
for _, p := range projects.List() {
if o.Project == p {
fmt.Fprintf(o.Out, " * %s\n", p)
} else {
fmt.Fprintf(o.Out, " %s\n", p)
}
}
fmt.Fprintln(o.Out)
}
fmt.Fprintln(o.Out)
fmt.Fprintf(o.Out, "Using project %q.\n", o.Project)
}

Expand Down Expand Up @@ -405,3 +409,8 @@ func (o *LoginOptions) serverProvided() bool {
func (o *LoginOptions) tokenProvided() bool {
return len(o.Token) > 0
}

func (o *LoginOptions) silentLogin() bool {
return o.Silent
}

0 comments on commit 1ae2adf

Please sign in to comment.