mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-09-11 05:19:11 +00:00
kubens: Start implementing stubs
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
44
cmd/kubens/help.go
Normal file
44
cmd/kubens/help.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// HelpOp describes printing help.
|
||||
type HelpOp struct{}
|
||||
|
||||
func (_ HelpOp) Run(stdout, _ io.Writer) error {
|
||||
return printUsage(stdout)
|
||||
}
|
||||
|
||||
func printUsage(out io.Writer) error {
|
||||
help := `USAGE:
|
||||
%PROG% : list the namespaces in the current context
|
||||
%PROG% <NAME> : change the active namespace of current context
|
||||
%PROG% - : switch to the previous namespace in this context
|
||||
%PROG% -c, --current : show the current namespace
|
||||
%PROG% -h,--help : show this message
|
||||
`
|
||||
// TODO this replace logic is duplicated between this and kubectx
|
||||
help = strings.ReplaceAll(help, "%PROG%", selfName())
|
||||
|
||||
_, err := fmt.Fprintf(out, "%s\n", help)
|
||||
return errors.Wrap(err, "write error")
|
||||
}
|
||||
|
||||
// selfName guesses how the user invoked the program.
|
||||
func selfName() string {
|
||||
// TODO this method is duplicated between this and kubectx
|
||||
me := filepath.Base(os.Args[0])
|
||||
pluginPrefix := "kubectl-"
|
||||
if strings.HasPrefix(me, pluginPrefix) {
|
||||
return "kubectl " + strings.TrimPrefix(me, pluginPrefix)
|
||||
}
|
||||
return "kubectx"
|
||||
}
|
Reference in New Issue
Block a user