-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
388efef
commit 5cb9075
Showing
6 changed files
with
50 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
module github.com/LuciferInLove/dynamic-sshmenu-aws | ||
|
||
go 1.16 | ||
go 1.20 | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go v1.33.15 | ||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e | ||
github.com/manifoldco/promptui v0.9.0 | ||
github.com/urfave/cli/v2 v2.3.0 | ||
) | ||
|
||
require ( | ||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/kr/text v0.2.0 // indirect | ||
github.com/lunixbochs/vtclean v1.0.0 // indirect | ||
github.com/manifoldco/promptui v0.8.0 | ||
github.com/mattn/go-colorable v0.1.7 // indirect | ||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect | ||
github.com/jmespath/go-jmespath v0.3.0 // indirect | ||
github.com/russross/blackfriday/v2 v2.0.1 // indirect | ||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect | ||
github.com/stretchr/testify v1.6.1 // indirect | ||
github.com/urfave/cli/v2 v2.3.0 | ||
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1 // indirect | ||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect | ||
) | ||
|
||
replace github.com/manifoldco/promptui v0.8.0 => github.com/LuciferInLove/promptui v0.7.1-0.20201003113208-3398ab7c53db | ||
replace github.com/manifoldco/promptui => github.com/LuciferInLove/promptui v0.0.0-20230609205938-268a0ead47b0 |
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
File renamed without changes.
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,7 +1,6 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
@@ -13,16 +12,9 @@ import ( | |
"github.com/urfave/cli/v2" | ||
) | ||
|
||
type instance struct { | ||
Number int | ||
IP string | ||
Name string | ||
Zone string | ||
} | ||
|
||
var ( | ||
connectTo string | ||
version = "v0.1.1" | ||
version = "v0.1.2" | ||
appAuthor *cli.Author = &cli.Author{ | ||
Name: "LuciferInLove", | ||
Email: "[email protected]", | ||
|
@@ -149,53 +141,43 @@ func promptSelect(instances []string) (string, error) { | |
_, result, err := prompt.Run() | ||
|
||
if err != nil { | ||
if err == promptui.ErrInterrupt { | ||
return result, fmt.Errorf("Interrupted by \"%w\"", err) | ||
} else if err == promptui.ErrEOF { | ||
return result, fmt.Errorf("Unexpected end of file: \"%w\"", err) | ||
} else { | ||
return result, err | ||
} | ||
return result, err | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func parseInstance(element string) (instance, error) { | ||
var instanceParsed instance | ||
if err := json.Unmarshal([]byte(element), &instanceParsed); err != nil { | ||
return instanceParsed, err | ||
} | ||
|
||
return instanceParsed, nil | ||
} | ||
|
||
func action(c *cli.Context) error { | ||
username := c.String("ssh-username") | ||
instances, err := getSliceOfInstances(c.String("tags"), c.String("display-name"), c.Bool("public-ip")) | ||
|
||
instances, err := getSliceOfInstances(c.String("tags"), c.String("display-name"), c.Bool("public-ip")) | ||
if err != nil { | ||
if err.Error() == "WrongTagDefinition" { | ||
cli.ShowAppHelp(c) | ||
return fmt.Errorf("\nIncorrect Usage. Wrong tag definition in flag -t") | ||
} | ||
return fmt.Errorf("There was an error listing instances in:\n%w", err) | ||
//return fmt.Errorf("Listing AWS instances:\n%w", err) | ||
instances = []string{`{"Number":1,"IP":"172.16.0.11","Name":"test-instance","Zone":"us-east-1a"}`} | ||
} | ||
|
||
result, err := promptSelect(instances) | ||
|
||
if err != nil { | ||
return err | ||
switch err { | ||
case promptui.ErrInterrupt: | ||
return nil | ||
case promptui.ErrEOF: | ||
return fmt.Errorf("Unexpected end of file: \"%w\"", err) | ||
default: | ||
return err | ||
} | ||
} | ||
|
||
instanceFromResult, err := parseInstance(result) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
sshPath, err := exec.LookPath(sshExecutable) | ||
|
||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
@@ -210,8 +192,8 @@ func action(c *cli.Context) error { | |
cmd.Stdin = os.Stdin | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
err = cmd.Run() | ||
|
||
err = cmd.Run() | ||
if err != nil { | ||
return fmt.Errorf("Command finished with an error, ssh: %w", err) | ||
} | ||
|