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
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Options for analysis running.
run:
print-resources-usage: true
timeout: 30m

# Use all default linters + those defined here
linters:
enable:
- gosec
- gosec
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ The newly create profile can now be configured via the `pingcli config set` comm
See [Configuration Key Documentation](./docs/tool-configuration/configuration-key.md) for more information on configuration keys
and their purposes.

See [Autocompletion Documentation](./docs/autocompletion/autocompletion.md) for information on loading autocompletion for select command flags.

## Commands

Ping CLI commands have the following structure:
Expand Down
76 changes: 76 additions & 0 deletions cmd/completion/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package completion

import (
"fmt"

"github.com/spf13/cobra"
)

const (
desc = `To load completions:

Bash:

$ source <(%[1]s completion bash)

# To load completions for each session, execute once:
# Linux:
$ %[1]s completion bash > /etc/bash_completion.d/%[1]s
# macOS:
$ source <(%[1]s completion zsh)

Zsh:

# If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once:

$ echo "autoload -U compinit; compinit" >> ~/.zshrc

# To load completions for each session, execute once:
$ %[1]s completion zsh > "${fpath[1]}/_%[1]s"

# You will need to start a new shell for this setup to take effect.

fish:

$ %[1]s completion fish | source

# To load completions for each session, execute once:
$ %[1]s completion fish > ~/.config/fish/completions/%[1]s.fish

PowerShell:

PS> %[1]s completion powershell | Out-String | Invoke-Expression

# To load completions for every new session, run:
PS> %[1]s completion powershell > %[1]s.ps1
# and source this file from your PowerShell profile.
`
)

func completionCmdRunE(cmd *cobra.Command, args []string) error {
switch args[0] {
case "bash":
_ = cmd.Root().GenBashCompletionV2(cmd.OutOrStdout(), true)
case "zsh":
_ = cmd.Root().GenZshCompletion(cmd.OutOrStdout())
case "fish":
_ = cmd.Root().GenFishCompletion(cmd.OutOrStdout(), true)
case "powershell":
_ = cmd.Root().GenPowerShellCompletion(cmd.OutOrStdout())
}

return nil
}

func Command() *cobra.Command {
cmd := &cobra.Command{
Use: "completion [SHELL]",
Short: "Prints shell completion scripts",
Long: fmt.Sprintf(desc, "pingcli"),
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
RunE: completionCmdRunE,
}
return cmd
}
14 changes: 14 additions & 0 deletions cmd/completion/cmd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package completion_test

import (
"testing"

"github.com/pingidentity/pingcli/internal/testing/testutils"
"github.com/pingidentity/pingcli/internal/testing/testutils_cobra"
)

// Test Completion Command Executes without issue
func TestCompletionCmd_Execute(t *testing.T) {
err := testutils_cobra.ExecutePingcli(t)
testutils.CheckExpectedError(t, err, nil)
}
8 changes: 5 additions & 3 deletions cmd/config/delete_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"

"github.com/pingidentity/pingcli/cmd/common"
"github.com/pingidentity/pingcli/internal/autocompletion"
config_internal "github.com/pingidentity/pingcli/internal/commands/config"
"github.com/pingidentity/pingcli/internal/configuration/options"
"github.com/pingidentity/pingcli/internal/logger"
Expand All @@ -29,9 +30,10 @@ func NewConfigDeleteProfileCommand() *cobra.Command {
Long: `Delete an existing custom configuration profile from the CLI.

The profile to delete will be removed from the CLI configuration file.`,
RunE: configDeleteProfileRunE,
Short: "Delete a custom configuration profile.",
Use: "delete-profile [flags] [profile-name]",
RunE: configDeleteProfileRunE,
Short: "Delete a custom configuration profile.",
Use: "delete-profile [flags] [profile-name]",
ValidArgsFunction: autocompletion.ConfigReturnNonActiveProfilesFunc,
}

cmd.Flags().AddFlag(options.ConfigDeleteAutoAcceptOption.Flag)
Expand Down
12 changes: 7 additions & 5 deletions cmd/config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"github.com/pingidentity/pingcli/cmd/common"
config_internal "github.com/pingidentity/pingcli/internal/commands/config"
"github.com/pingidentity/pingcli/internal/configuration"
"github.com/pingidentity/pingcli/internal/logger"
"github.com/spf13/cobra"
)
Expand All @@ -11,8 +12,8 @@ const (
configGetCommandExamples = ` Read all the configuration settings for the PingOne service in the active (or default) profile.
pingcli config get pingone

Read the color setting for the profile named 'myProfile'.
pingcli config get --profile myProfile color
Read the noColor setting for the profile named 'myProfile'.
pingcli config get --profile myProfile noColor

Read the worker ID used to authenticate to the PingOne service management API.
pingcli config get service.pingone.authentication.worker.environmentID`
Expand All @@ -26,9 +27,10 @@ func NewConfigGetCommand() *cobra.Command {
Long: "Read stored configuration settings for the CLI.\n\n" +
"The `--profile` parameter can be used to read configuration settings for a specified custom configuration profile.\n" +
"Where `--profile` is not specified, configuration settings will be read for the currently active profile.",
RunE: configGetRunE,
Short: "Read stored configuration settings for the CLI.",
Use: "get [flags] key",
RunE: configGetRunE,
Short: "Read stored configuration settings for the CLI.",
Use: "get [flags] key",
ValidArgs: configuration.ViperKeys(),
}

return cmd
Expand Down
8 changes: 5 additions & 3 deletions cmd/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"github.com/pingidentity/pingcli/cmd/common"
config_internal "github.com/pingidentity/pingcli/internal/commands/config"
"github.com/pingidentity/pingcli/internal/configuration"
"github.com/pingidentity/pingcli/internal/logger"
"github.com/spf13/cobra"
)
Expand All @@ -23,9 +24,10 @@ func NewConfigSetCommand() *cobra.Command {
Long: "Set stored configuration settings for the CLI.\n\n" +
"The `--profile` parameter can be used to set configuration settings for a specified custom configuration profile.\n" +
"Where `--profile` is not specified, configuration settings will be set for the currently active profile.",
RunE: configSetRunE,
Short: "Set stored configuration settings for the CLI.",
Use: "set [flags] key=value",
RunE: configSetRunE,
Short: "Set stored configuration settings for the CLI.",
Use: "set [flags] key=value",
ValidArgs: configuration.ViperKeys(),
}

return cmd
Expand Down
3 changes: 3 additions & 0 deletions cmd/config/set_active_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"

"github.com/pingidentity/pingcli/cmd/common"
"github.com/pingidentity/pingcli/internal/autocompletion"
config_internal "github.com/pingidentity/pingcli/internal/commands/config"
"github.com/pingidentity/pingcli/internal/logger"
"github.com/spf13/cobra"
Expand All @@ -26,6 +27,8 @@ func NewConfigSetActiveProfileCommand() *cobra.Command {
RunE: configSetActiveProfileRunE,
Short: "Set a custom configuration profile as the in-use profile.",
Use: "set-active-profile [flags] [profile-name]",
// Auto-completion function to return all valid profile names
ValidArgsFunction: autocompletion.ConfigReturnNonActiveProfilesFunc,
}

return cmd
Expand Down
8 changes: 5 additions & 3 deletions cmd/config/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"github.com/pingidentity/pingcli/cmd/common"
config_internal "github.com/pingidentity/pingcli/internal/commands/config"
"github.com/pingidentity/pingcli/internal/configuration"
"github.com/pingidentity/pingcli/internal/logger"
"github.com/spf13/cobra"
)
Expand All @@ -23,9 +24,10 @@ func NewConfigUnsetCommand() *cobra.Command {
Long: "Unset stored configuration settings for the CLI.\n\n" +
"The `--profile` parameter can be used to unset configuration settings for a specified custom configuration profile.\n" +
"Where `--profile` is not specified, configuration settings will be unset for the currently active profile.",
RunE: configUnsetRunE,
Short: "Unset stored configuration settings for the CLI.",
Use: "unset [flags] key",
RunE: configUnsetRunE,
Short: "Unset stored configuration settings for the CLI.",
Use: "unset [flags] key",
ValidArgs: configuration.ViperKeys(),
}

return cmd
Expand Down
3 changes: 3 additions & 0 deletions cmd/config/view_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"github.com/pingidentity/pingcli/cmd/common"
"github.com/pingidentity/pingcli/internal/autocompletion"
config_internal "github.com/pingidentity/pingcli/internal/commands/config"
"github.com/pingidentity/pingcli/internal/logger"
"github.com/spf13/cobra"
Expand All @@ -24,6 +25,8 @@ func NewConfigViewProfileCommand() *cobra.Command {
RunE: configViewProfileRunE,
Short: "View the stored configuration of a custom configuration profile.",
Use: "view-profile [flags] [profile-name]",
// Auto-completion function to return all valid profile names
ValidArgsFunction: autocompletion.ConfigViewProfileFunc,
}

return cmd
Expand Down
24 changes: 22 additions & 2 deletions cmd/platform/export.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package platform

import (
"fmt"

"github.com/pingidentity/pingcli/cmd/common"
"github.com/pingidentity/pingcli/internal/autocompletion"
platform_internal "github.com/pingidentity/pingcli/internal/commands/platform"
"github.com/pingidentity/pingcli/internal/configuration/options"
"github.com/pingidentity/pingcli/internal/logger"
"github.com/pingidentity/pingcli/internal/output"
"github.com/spf13/cobra"
)

Expand All @@ -16,7 +20,7 @@ const (
pingcli platform export --output-directory /path/to/my/directory --overwrite

Export configuration-as-code packages for all configured products, specifying the export format as Terraform HCL.
pingcli platform export --export-format HCL
pingcli platform export --format HCL

Export configuration-as-code packages for PingOne (core platform and SSO services).
pingcli platform export --services pingone-platform,pingone-sso
Expand Down Expand Up @@ -56,6 +60,22 @@ func NewExportCommand() *cobra.Command {
initPingFederateAccessTokenFlags(cmd)
initPingFederateClientCredentialsFlags(cmd)

// auto-completion
err := cmd.RegisterFlagCompletionFunc(options.PlatformExportExportFormatOption.CobraParamName, autocompletion.PlatformExportFormatFunc)
if err != nil {
output.SystemError(fmt.Sprintf("Unable to register auto completion for platform export flag %s: %v", options.PlatformExportExportFormatOption.CobraParamName, err), nil)
}

err = cmd.RegisterFlagCompletionFunc(options.PlatformExportServiceOption.CobraParamName, autocompletion.PlatformExportServicesFunc)
if err != nil {
output.SystemError(fmt.Sprintf("Unable to register auto completion for platform export flag %s: %v", options.PlatformExportServiceOption.CobraParamName, err), nil)
}

err = cmd.RegisterFlagCompletionFunc(options.PingOneAuthenticationTypeOption.CobraParamName, autocompletion.PlatformExportPingOneAuthenticationTypeFunc)
if err != nil {
output.SystemError(fmt.Sprintf("Unable to register auto completion for platform export flag %s: %v", options.PingOneAuthenticationTypeOption.CobraParamName, err), nil)
}

return cmd
}

Expand All @@ -79,8 +99,8 @@ func initPingOneExportFlags(cmd *cobra.Command) {
cmd.Flags().AddFlag(options.PingOneAuthenticationWorkerEnvironmentIDOption.Flag)
cmd.Flags().AddFlag(options.PingOneAuthenticationWorkerClientIDOption.Flag)
cmd.Flags().AddFlag(options.PingOneAuthenticationWorkerClientSecretOption.Flag)
cmd.Flags().AddFlag(options.PingOneRegionCodeOption.Flag)
cmd.Flags().AddFlag(options.PingOneAuthenticationTypeOption.Flag)
cmd.Flags().AddFlag(options.PingOneRegionCodeOption.Flag)

cmd.MarkFlagsRequiredTogether(
options.PingOneAuthenticationWorkerEnvironmentIDOption.CobraParamName,
Expand Down
36 changes: 30 additions & 6 deletions cmd/request/request.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package request

import (
"fmt"

"github.com/pingidentity/pingcli/cmd/common"
"github.com/pingidentity/pingcli/internal/autocompletion"
request_internal "github.com/pingidentity/pingcli/internal/commands/request"
"github.com/pingidentity/pingcli/internal/configuration/options"
"github.com/pingidentity/pingcli/internal/logger"
"github.com/pingidentity/pingcli/internal/output"
"github.com/spf13/cobra"
)

Expand All @@ -15,11 +19,11 @@ const (
Send a custom API request to the configured PingOne tenant, making a GET request to retrieve JSON configuration for a specific environment.
pingcli request --service pingone --http-method GET --output-format json environments/$MY_ENVIRONMENT_ID

Send a custom API request to the configured PingOne tenant, making a POST request to create a new environment using raw JSON data.
pingcli request --service pingone --http-method POST --data '{"name": "My environment"}' environments

Send a custom API request to the configured PingOne tenant, making a POST request to create a new environment with JSON data sourced from a file.
pingcli request --service pingone --http-method POST --data @./my-environment.json environments
pingcli request --service pingone --http-method POST --data ./my-environment.json environments

Send a custom API request to the configured PingOne tenant, making a POST request to create a new environment using raw JSON data.
pingcli request --service pingone --http-method POST --data-raw '{"name": "My environment"}' environments

Send a custom API request to the configured PingOne tenant, making a DELETE request to remove an application attribute mapping.
pingcli request --service pingone --http-method DELETE environments/$MY_ENVIRONMENT_ID/applications/$MY_APPLICATION_ID/attributes/$MY_ATTRIBUTE_MAPPING_ID`
Expand All @@ -39,11 +43,31 @@ The command offers a cURL-like experience to interact with the Ping platform ser
Use: "request [flags] API_URI",
}

cmd.Flags().AddFlag(options.RequestHTTPMethodOption.Flag)
cmd.Flags().AddFlag(options.RequestServiceOption.Flag)
// --data
cmd.Flags().AddFlag(options.RequestDataOption.Flag)

// --data-raw
cmd.Flags().AddFlag(options.RequestDataRawOption.Flag)

// --fail, -f
cmd.Flags().AddFlag(options.RequestFailOption.Flag)

// --http-method, -m
cmd.Flags().AddFlag(options.RequestHTTPMethodOption.Flag)
// auto-completion
err := cmd.RegisterFlagCompletionFunc(options.RequestHTTPMethodOption.CobraParamName, autocompletion.RequestHTTPMethodFunc)
if err != nil {
output.SystemError(fmt.Sprintf("Unable to register auto completion for request flag %s: %v", options.RequestHTTPMethodOption.CobraParamName, err), nil)
}

// --service, -s
cmd.Flags().AddFlag(options.RequestServiceOption.Flag)
// auto-completion
err = cmd.RegisterFlagCompletionFunc(options.RequestServiceOption.CobraParamName, autocompletion.RequestServiceFunc)
if err != nil {
output.SystemError(fmt.Sprintf("Unable to register auto completion for request flag %s: %v", options.RequestServiceOption.CobraParamName, err), nil)
}

return cmd
}

Expand Down
Loading
Loading