diff --git a/CHANGELOG.md b/CHANGELOG.md index 1db66fb..16f082f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.1.2] - 2023-06-09 + +### Changed +- promptui has been updated to v0.8.0 +- go has been updated to v1.20 + ## [0.1.1] - 2021-11-14 ### Changed @@ -47,7 +53,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial release -[unreleased]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.1.1...HEAD +[unreleased]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.1.2...HEAD +[0.1.2]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.1.1...v0.1.2 [0.1.1]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.1.0...v0.1.1 [0.1.0]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.0.5...v0.1.0 [0.0.5]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.0.4...v0.0.5 diff --git a/go.mod b/go.mod index 546c7dc..8d32fd3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 10dcca8..4af1a7e 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/LuciferInLove/promptui v0.7.1-0.20201003113208-3398ab7c53db h1:1W+7EPFv+cNIapVnW/9S1ss2TWPBzr/K1OwlmdstPF4= -github.com/LuciferInLove/promptui v0.7.1-0.20201003113208-3398ab7c53db/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ= +github.com/LuciferInLove/promptui v0.0.0-20230609205938-268a0ead47b0 h1:BAUNHD0LioG9JlPKRSE4LMHSpqj3INWJ3a9osF6N49s= +github.com/LuciferInLove/promptui v0.0.0-20230609205938-268a0ead47b0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= github.com/aws/aws-sdk-go v1.33.15 h1:JiYid0lBDcM12HNOND5EcaBd1namBuB5BJ4Iex0DFMw= github.com/aws/aws-sdk-go v1.33.15/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= @@ -12,31 +12,12 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc= github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= -github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU= -github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= -github.com/lunixbochs/vtclean v1.0.0 h1:xu2sLAri4lGiovBDQKxl5mrXyESr3gUr5m5SM5+LVb8= -github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw= -github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -54,15 +35,10 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1 h1:sIky/MyNRSHTrdxfsiUSS4WIAMvInbeXljJz+jDjeYE= golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/instances.go b/instances.go index f792952..052e037 100644 --- a/instances.go +++ b/instances.go @@ -10,6 +10,22 @@ import ( "github.com/aws/aws-sdk-go/service/ec2" ) +type instance struct { + Number int + IP string + Name string + Zone string +} + +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 getSliceOfInstances(tags string, displayName string, publicIP bool) ([]string, error) { var ( i int = 1 diff --git a/main_test.go b/instances_test.go similarity index 100% rename from main_test.go rename to instances_test.go diff --git a/main.go b/main.go index d3b8eb9..d4b56ca 100644 --- a/main.go +++ b/main.go @@ -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: "lucifer.in.love@protonmail.com", @@ -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) }