This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
/
commands.go
65 lines (54 loc) · 1.76 KB
/
commands.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
65
// Package commands contains all of the cli commands
package commands // import "github.com/nginxinc/nginx-service-mesh/internal/nginx-meshctl/commands"
import (
"bufio"
"errors"
"fmt"
"os"
"text/tabwriter"
"github.com/spf13/cobra"
// client-go auth methods.
_ "k8s.io/client-go/plugin/pkg/client/auth"
)
// Setup creates the root command and adds all sub commands.
func Setup(cmdName, version, commit string) *cobra.Command {
return AddSubCommands(cmdName, version, commit, Root(cmdName))
}
// AddSubCommands adds all subcommands to the root command.
func AddSubCommands(cmdName, version, commit string, rootCmd *cobra.Command) *cobra.Command {
rootCmd.AddCommand(NewStatusCmd())
rootCmd.AddCommand(NewVersionCmd(cmdName, version, commit))
rootCmd.AddCommand(Top())
rootCmd.AddCommand(GetServices())
rootCmd.AddCommand(GetConfig())
rootCmd.AddCommand(Inject())
rootCmd.AddCommand(Deploy())
rootCmd.AddCommand(Upgrade(version))
rootCmd.AddCommand(Remove())
rootCmd.AddCommand(Support(version))
return rootCmd
}
var errCommandStopped = errors.New("command stopped by user")
// ReadYes reads user input to make a yes/no decision.
func ReadYes(msg string) error {
reader := bufio.NewReader(os.Stdin)
fmt.Println(msg)
fmt.Print("Do you want to continue (y/n)? ")
letter, _, _ := reader.ReadRune()
switch letter {
case 'Y', 'y':
break
default:
fmt.Println()
return errCommandStopped
}
fmt.Println()
return nil
}
/* TabWriterWithOpts returns a tabwriter.
* This call, with these numbers were found across the codebase
* and so were centralized here so that modifications to text attributes
* could be made from one place.*/
func TabWriterWithOpts() *tabwriter.Writer {
return tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0) //nolint:gomnd // ignore text opts
}