Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"github.com/elasticpath/epcc-cli/external/authentication"
"github.com/elasticpath/epcc-cli/external/completion"
"github.com/elasticpath/epcc-cli/globals"
"github.com/spf13/cobra"
"os"
Expand Down Expand Up @@ -62,4 +63,20 @@ var login = &cobra.Command{

return err
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
return completion.Complete(completion.Request{
Type: completion.CompleteLoginLogoutAPI,
})
} else if len(args) == 1 {
return completion.Complete(completion.Request{
Type: completion.CompleteLoginClientID,
})
} else if len(args) == 3 {
return completion.Complete(completion.Request{
Type: completion.CompleteLoginClientSecret,
})
}
return []string{}, cobra.ShellCompDirectiveNoFileComp
},
}
9 changes: 9 additions & 0 deletions cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/elasticpath/epcc-cli/external/completion"
"github.com/elasticpath/epcc-cli/globals"
"github.com/spf13/cobra"
"os"
Expand Down Expand Up @@ -33,4 +34,12 @@ var logout = &cobra.Command{
}
return err
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
return completion.Complete(completion.Request{
Type: completion.CompleteLoginLogoutAPI,
})
}
return []string{}, cobra.ShellCompDirectiveNoFileComp
},
}
29 changes: 22 additions & 7 deletions external/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import (
)

const (
CompletePluralResource = 1
CompleteSingularResource = 2
CompleteAttributeKey = 4
CompleteAttributeValue = 8
CompleteQueryParam = 16
CompleteCrudAction = 32
CompleteAlias = 64
CompletePluralResource = 1
CompleteSingularResource = 2
CompleteAttributeKey = 4
CompleteAttributeValue = 8
CompleteQueryParam = 16
CompleteCrudAction = 32
CompleteAlias = 64
CompleteLoginLogoutAPI = 128
CompleteLoginClientID = 256
CompleteLoginClientSecret = 1024
)

const (
Expand Down Expand Up @@ -81,6 +84,18 @@ func Complete(c Request) ([]string, cobra.ShellCompDirective) {
results = append(results, "create", "update", "delete", "get")
}

if c.Type&CompleteLoginLogoutAPI > 0 {
results = append(results, "api")
}

if c.Type&CompleteLoginClientID > 0 {
results = append(results, "client_id")
}

if c.Type&CompleteLoginClientSecret > 0 {
results = append(results, "client_secret")
}

if c.Type&CompleteAttributeKey > 0 {
for k := range c.Resource.Attributes {
if strings.Contains(k, "[n]") {
Expand Down