/
cmd.go
69 lines (59 loc) · 1.42 KB
/
cmd.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
66
67
68
69
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
// AppVersion info.
var AppVersion string
// AppBuild info.
var AppBuild string
// AppDate info.
var AppDate string
var config string
var interactive bool
var version bool
// RootCmd - Entry point to the application.
var RootCmd = &cobra.Command{
Use: "konnect",
Short: "Connect to SSH hosts.",
Long: "Konnect is a tool to define and connect to SSH hosts.",
Run: func(cmd *cobra.Command, args []string) {
// Perform interactive connect prompt.
if err := interactivePrompt(cmd); err != nil {
if err == errConfigNotFound {
cmd.Help()
fmt.Println()
}
handleErr(err)
}
},
PreRun: func(cmd *cobra.Command, args []string) {
if version {
fmt.Println(AppVersion)
os.Exit(0)
}
},
}
func init() {
// Config filename.
RootCmd.PersistentFlags().StringVarP(&config, "filename", "f", "", "Specify config file")
// Show version information.
RootCmd.Flags().BoolVarP(&version, "version", "v", false, "View version information")
}
// AddCommands - Connects subcommands to the RootCmd.
func AddCommands() {
ConnectCmd.AddCommand(TaskCmd)
RootCmd.AddCommand(ArgsCmd)
RootCmd.AddCommand(ConnectCmd)
RootCmd.AddCommand(InitCmd)
RootCmd.AddCommand(ListCmd)
RootCmd.AddCommand(EditCmd)
RootCmd.AddCommand(StatusCmd)
RootCmd.AddCommand(VersionCmd)
}
// Execute - runs the RootCmd.
func Execute() error {
AddCommands()
return RootCmd.Execute()
}