Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AppBuild string
AppBuild info.
View Source
var AppDate string
AppDate info.
View Source
var AppVersion string
AppVersion info.
View Source
var ArgsCmd = &cobra.Command{ Use: "args", Short: "Print the SSH command for a host", Long: "Print the SSH command for a host", Run: func(cmd *cobra.Command, args []string) { filename, err := resolveFilename(cmd) handleErr(err) if len(args) != 1 { log.Fatal(errHostRequired) } host := args[0] konnect, err := engine.Init(filename) handleErr(err) proxy, err := konnect.GetHost(host) handleErr(err) argsStr := strings.Join(proxy.Args(), " ") fmt.Println(argsStr) }, }
ArgsCmd - Print the SSH command for a host.
View Source
var ConnectCmd = &cobra.Command{ Use: "to", Short: "Connect to a host", Long: "Connect to a host", Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { log.Fatal(errHostRequired) } hostName = args[0] if len(args) == 1 { err := connectToHost(cmd, hostName, "") handleErr(err) os.Exit(0) } subCmd, subArgs, err := cmd.Find(args[1:]) handleErr(err) if subCmd.Use == cmd.Use { log.Fatalf("Cannot parse subcommand %v\n", subArgs) } else { subCmd.Run(cmd, subArgs) } }, }
ConnectCmd - Connect to a host.
View Source
var EditCmd = &cobra.Command{ Use: "edit", Short: "Open the config file with the default editor", Long: "Open the config file with the default editor", Run: func(cmd *cobra.Command, args []string) { filename, err := resolveFilename(cmd) handleErr(err) fmt.Printf("Opening config file at %v\n", filename) if err := exec.Command("open", filename).Run(); err != nil { log.Fatal("Error when opening the config file.") } }, }
EditCmd - Open the konnect.yml config file with the default editor.
View Source
var InitCmd = &cobra.Command{ Use: "init", Short: "Initialize a konnect.yml configuration file at the given directory.", Long: "Initialize a konnect.yml configuration file at the given directory.", Run: func(cmd *cobra.Command, args []string) { dir := "." if len(args) > 1 { log.Fatal("Too many args. Please specify a directory") } if len(args) == 1 { dir = args[0] } dir, _ = filepath.Abs(dir) localFilename := getDefaultConfigs()[0] filename := filepath.Join(dir, localFilename) if _, err := os.Stat(filename); err == nil { log.Fatalf("File %v already exists.\n", filename) } if err := makeDefaultConfig(filename); err != nil { log.Fatal(err) } }, }
InitCmd - Create configuration file.
View Source
var ListCmd = &cobra.Command{ Use: "list", Short: "List all hosts", Long: "List all hosts", Run: func(cmd *cobra.Command, args []string) { filename, err := resolveFilename(cmd) handleErr(err) konnect, err := engine.Init(filename) handleErr(err) hostList := [][]string{} for _, hostName := range konnect.GetHostNames() { hostInfo := konnect.Hosts[hostName].Info() hostList = append(hostList, []string{ hostName, hostInfo, }) } hostTable := tablewriter.NewWriter(os.Stdout) hostTable.SetHeader([]string{"Hosts", ""}) hostTable.AppendBulk(hostList) hostTable.Render() fmt.Printf("\n\n") taskList := [][]string{} for _, taskName := range konnect.GetTaskNames() { taskInfo := konnect.Tasks[taskName].Info() taskList = append(taskList, []string{ taskName, taskInfo, }) } taskTable := tablewriter.NewWriter(os.Stdout) taskTable.SetHeader([]string{"Tasks", ""}) taskTable.AppendBulk(taskList) taskTable.Render() }, }
ListCmd - List all hosts from config file.
View Source
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) { 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) } }, }
RootCmd - Entry point to the application.
View Source
var StatusCmd = &cobra.Command{ Use: "status", Short: "Check the status of one or more hosts", Long: "Check the status of one or more hosts", Run: func(cmd *cobra.Command, args []string) { filename, err := resolveFilename(cmd) handleErr(err) konnect, err := engine.Init(filename) handleErr(err) hosts := args if allHosts == true { hosts = konnect.GetHostNames() } if allHosts == true && len(args) > 0 { log.Fatal("Cannot use --all with specific hosts") } if allHosts == false && len(args) == 0 { log.Fatal(errHostsRequired) } hosts = removeDuplicates(hosts) if err := konnect.CheckHosts(hosts); err != nil { log.Fatal(err) } fmt.Printf("Testing connections for %v\n\n", strings.Join(hosts, ", ")) konnect.Status(hosts) }, }
StatusCmd - Check the status of one or more hosts.
View Source
var TaskCmd = &cobra.Command{ Use: "and", Short: "Run a task on a host", Long: "Run a task on a host", Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { log.Fatal(errTaskRequired) } taskName = args[0] err := connectToHost(cmd, hostName, taskName) handleErr(err) }, }
TaskCmd - Run a task on a host.
View Source
var VersionCmd = &cobra.Command{ Use: "version", Short: "Show detailed version information", Long: "Show detailed version information", Run: func(cmd *cobra.Command, args []string) { fmt.Println("Konnect:") fmt.Printf(" version %v\n", AppVersion) fmt.Printf(" build %v\n", AppBuild) fmt.Printf(" date %v\n", AppDate) }, }
VersionCmd - Show detailed version information.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.