Skip to content

Commit

Permalink
Fix for breaking changes in openapi lib (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
buzzy authored Jan 5, 2024
1 parent 43d0753 commit 3bac421
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
16 changes: 8 additions & 8 deletions autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ func listComplete(items []string, prefix string) {

}

//List basic flags
// List basic flags
func autoBasic(flags []string) {

if flags[0] != "" && flags[0][:1] == "-" && len(flags) == 1 {
listComplete([]string{"-version ", "-help ", "-verbose ", "-configure ", "-update ", "-autocomplete "}, flags[0])
}
}

//List all available commands
// List all available commands
func autoCommands(allFlags map[string]map[string][]string, flags []string, prefix string) {
if len(flags) <= 1 || (len(flags) == 2 && flags[0][:1] == "-") {

Expand All @@ -87,7 +87,7 @@ func autoCommands(allFlags map[string]map[string][]string, flags []string, prefi
}
}

//List flags for specific command
// List flags for specific command
func autoFlags(allFlags map[string]map[string][]string, flags []string, command string, prefix string) {

var params []string
Expand All @@ -100,7 +100,7 @@ func autoFlags(allFlags map[string]map[string][]string, flags []string, command

}

//List flag-options for specific flag
// List flag-options for specific flag
func autoOptions(allFlags map[string]map[string][]string, command string, prefix string) {
if strings.Contains(prefix, "=") {

Expand All @@ -126,14 +126,14 @@ func autoOptions(allFlags map[string]map[string][]string, command string, prefix
}
}

//Load all available flags and options from OpenAPI
// Load all available flags and options from OpenAPI
func collectFlagsAndOptions() map[string]map[string][]string {

allFlags := make(map[string]map[string][]string)

doc := loadAPI()

for _, path := range doc.Paths {
for _, path := range doc.Paths.Map() {
for _, object := range path.Operations() {

command := strings.ReplaceAll(object.OperationID, "_", "-")
Expand Down Expand Up @@ -321,7 +321,7 @@ func enableAutocomplete() {

}

//Install auto-complete for bash
// Install auto-complete for bash
func autoCompleteBash(home string, fname string) string {

theConfig := home + "/" + ".bashrc"
Expand Down Expand Up @@ -351,7 +351,7 @@ func autoCompleteBash(home string, fname string) string {
return theConfig
}

//Install auto-complete for zsh
// Install auto-complete for zsh
func autoCompleteZsh(home string, fname string) string {

theConfig := home + "/" + ".zshrc"
Expand Down
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func parseCommand(format string, verbose bool) {

command := flag.Arg(0)

for uri, path := range doc.Paths {
for uri, path := range doc.Paths.Map() {
for method, action := range path.Operations() {
if strings.ReplaceAll(action.OperationID, "_", "-") != command {
continue
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/Jeffail/gabs/v2 v2.7.0
github.com/getkin/kin-openapi v0.122.0
golang.org/x/term v0.15.0
golang.org/x/term v0.16.0
)

require (
Expand All @@ -16,6 +16,6 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
4 changes: 2 additions & 2 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func printHelp() {

groups := make(map[string]map[string]string)

for _, path := range doc.Paths {
for _, path := range doc.Paths.Map() {
for _, method := range path.Operations() {

group := ""
Expand Down Expand Up @@ -114,7 +114,7 @@ func printHelpCommand(command string) {
//Load OpenAPI specification
doc := loadAPI()

for _, path := range doc.Paths {
for _, path := range doc.Paths.Map() {
for method, object := range path.Operations() {

if command != strings.ReplaceAll(object.OperationID, "_", "-") {
Expand Down

0 comments on commit 3bac421

Please sign in to comment.