-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build functionality to connect to host and run task (via 'connectToHo…
…st' function).
- Loading branch information
Sandeep Jadoonanan
committed
Nov 13, 2017
1 parent
ac07067
commit f73fe4e
Showing
7 changed files
with
119 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,69 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/exitshell/konnect/engine" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var hostName string | ||
var taskName string | ||
|
||
// ConnectCmd - Connect to a host. | ||
var ConnectCmd = &cobra.Command{ | ||
Use: "to", | ||
Short: "Connect to a host", | ||
Long: "Connect to a host", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Resolve filename from flags. | ||
filename, err := resolveFilename(cmd) | ||
handleErr(err) | ||
fmt.Printf("[connectcmd] %v (%T)\n", args, args) | ||
|
||
// Check that only one host was specified. | ||
if len(args) != 1 { | ||
log.Fatal("Please specify one host") | ||
if len(args) == 0 { | ||
log.Fatal("Please specify a host") | ||
} | ||
host := args[0] | ||
|
||
// Init engine. | ||
konnect, err := engine.Init(filename) | ||
handleErr(err) | ||
// Set hostname. | ||
hostName = args[0] | ||
|
||
// Get host. | ||
proxy, err := konnect.Get(host) | ||
if len(args) == 1 { | ||
// Connect to host. | ||
err := connectToHost(cmd, hostName, "") | ||
handleErr(err) | ||
os.Exit(0) | ||
} | ||
|
||
// Find the subcommand. | ||
subCmd, subArgs, err := cmd.Find(args[1:]) | ||
handleErr(err) | ||
// If the subcommand is the same as the original command, | ||
// then no new subcommand was found. In that case, exit | ||
// with an error. | ||
if subCmd.Use == cmd.Use { | ||
log.Fatalf("Cannot parse subcommand %v\n", subArgs) | ||
} else { | ||
subCmd.Run(cmd, subArgs) | ||
} | ||
}, | ||
} | ||
|
||
// TaskCmd - Run a task on a host. | ||
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) { | ||
fmt.Printf("[taskcmd] %v (%T)\n", args, args) | ||
|
||
// Connect to host. | ||
if err := proxy.Connect(); err != nil { | ||
log.Fatal(err) | ||
if len(args) == 0 { | ||
log.Fatal("Please specify a task") | ||
} | ||
|
||
// Set task name. | ||
taskName = args[0] | ||
|
||
// Connect to host and run a command. | ||
err := connectToHost(cmd, hostName, taskName) | ||
handleErr(err) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters