Skip to content
Draft
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ require (
github.com/hashicorp/go-version v1.8.0
github.com/joho/godotenv v1.5.1
github.com/yuin/goldmark v1.2.1
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand All @@ -74,7 +75,6 @@ require (
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/sync v0.20.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
Expand Down
9 changes: 5 additions & 4 deletions pkg/cmd/community.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/cobra"

"github.com/stripe/stripe-cli/pkg/i18n"
"github.com/stripe/stripe-cli/pkg/open"
)

Expand All @@ -24,7 +25,7 @@ func newCommunityCmd() *communityCmd {
cc.cmd = &cobra.Command{
Use: "community",
Aliases: []string{"discord", "chat"},
Short: "Chat with Stripe engineers and other developers",
Short: i18n.T("community.short"),
Example: "stripe community",
RunE: cc.runCommunityCmd,
}
Expand All @@ -34,18 +35,18 @@ func newCommunityCmd() *communityCmd {

func (cc *communityCmd) runCommunityCmd(cmd *cobra.Command, args []string) error {
if !canOpenBrowser() {
fmt.Printf("Chat with other developers and Stripe engineers in the official Stripe Discord server: %s\n", communityURL)
fmt.Print(i18n.Tf("community.output.no_browser", i18n.Args{"url": communityURL}))
return nil
}

fmt.Printf("Chat with other developers and Stripe engineers in the official Stripe Discord server.\n\nPress Enter to open the browser or visit %s", communityURL)
fmt.Print(i18n.Tf("community.output.with_browser", i18n.Args{"url": communityURL}))

input := os.Stdin
fmt.Fscanln(input)

err := openBrowser(communityURL)
if err != nil {
fmt.Printf("Failed to open browser, please go to %s manually.", communityURL)
fmt.Print(i18n.Tf("community.output.browser_failed", i18n.Args{"url": communityURL}))
}

return nil
Expand Down
88 changes: 16 additions & 72 deletions pkg/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

"github.com/spf13/cobra"

"github.com/stripe/stripe-cli/pkg/i18n"
"github.com/stripe/stripe-cli/pkg/validators"
)

Expand All @@ -23,15 +24,15 @@

cc.cmd = &cobra.Command{
Use: "completion",
Short: "Generate bash, zsh, and fish completion scripts",
Short: i18n.T("completion.short"),
Args: validators.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return selectShell(cc.shell, cc.writeToStdout)
},
}

cc.cmd.Flags().StringVar(&cc.shell, "shell", "", "Shell to generate completions for: bash, zsh, or fish (auto-detected if omitted)")
cc.cmd.Flags().BoolVar(&cc.writeToStdout, "write-to-stdout", false, "Print completion script to stdout rather than creating a new file.")
cc.cmd.Flags().StringVar(&cc.shell, "shell", "", i18n.T("completion.flags.shell"))
cc.cmd.Flags().BoolVar(&cc.writeToStdout, "write-to-stdout", false, i18n.T("completion.flags.write_to_stdout"))

_ = cc.cmd.RegisterFlagCompletionFunc("shell", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"bash", "zsh", "fish"}, cobra.ShellCompDirectiveNoFileComp
Expand All @@ -40,64 +41,7 @@
return cc
}

const (
instructionsHeader = `
Suggested next steps:
---------------------`

zshCompletionInstructions = `
1. Move ` + "`stripe-completion.zsh`" + ` to the correct location:
mkdir -p ~/.stripe
mv stripe-completion.zsh ~/.stripe

2. Add the following lines to your ` + "`.zshrc`" + ` enabling shell completion for Stripe:
fpath=(~/.stripe $fpath)
autoload -Uz compinit && compinit -i

3. Source your ` + "`.zshrc`" + ` or open a new terminal session:
source ~/.zshrc`

bashCompletionInstructionsMac = `
Set up bash autocompletion on your system:
1. Install the bash autocompletion package:
brew install bash-completion
2. Follow the post-install instructions displayed by Homebrew; add a line like the following to your bash profile:
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

Set up Stripe autocompletion:
3. Move ` + "`stripe-completion.bash`" + ` to the correct location:
mkdir -p ~/.stripe
mv stripe-completion.bash ~/.stripe

4. Add the following line to your bash profile, so that Stripe autocompletion will be enabled every time you start a new terminal session:
source ~/.stripe/stripe-completion.bash

5. Either restart your terminal, or run the following command in your current session to enable immediately:
source ~/.stripe/stripe-completion.bash`

bashCompletionInstructionsLinux = `
1. Ensure bash autocompletion is installed on your system. Often, this means verifying that ` + "`/etc/profile.d/bash_completion.sh`" + ` exists, and is sourced by your bash profile; the location of this file varies across distributions of Linux.

2. Move ` + "`stripe-completion.bash`" + ` to the correct location:
mkdir -p ~/.stripe
mv stripe-completion.bash ~/.stripe

3. Add the following line to your bash profile, so that Stripe autocompletion will be enabled every time you start a new terminal session:
source ~/.stripe/stripe-completion.bash

4. Either restart your terminal, or run the following command in your current session to enable immediately:
source ~/.stripe/stripe-completion.bash`

fishCompletionInstructions = `
1. Move ` + "`stripe.fish`" + ` to the fish completions directory:
mkdir -p ~/.config/fish/completions
mv stripe.fish ~/.config/fish/completions/stripe.fish

Fish automatically loads completions from this directory, so no additional
configuration is needed. Open a new terminal session and completions will
be available.`
)

Check failure on line 44 in pkg/cmd/completion.go

View workflow job for this annotation

GitHub Actions / test (1.26.0, ubuntu-latest)

File is not properly formatted (gofmt)

Check failure on line 44 in pkg/cmd/completion.go

View workflow job for this annotation

GitHub Actions / test (1.26.0, macos-latest)

File is not properly formatted (gofmt)
func selectShell(shell string, writeToStdout bool) error {
selected := shell
autoDetected := false
Expand All @@ -115,9 +59,9 @@
return genFish(writeToStdout, autoDetected)
default:
if shell != "" {
return fmt.Errorf("unsupported shell %q; supported shells are: bash, zsh, fish", shell)
return fmt.Errorf("%s", i18n.Tf("completion.errors.unsupported_shell", i18n.Args{"shell": shell}))
}
return fmt.Errorf("could not automatically detect your shell; please run the command with the --shell flag for bash, zsh, or fish")
return fmt.Errorf("%s", i18n.T("completion.errors.cannot_detect_shell"))
}
}

Expand All @@ -127,14 +71,14 @@
}

if autoDetected {
fmt.Println("Detected `zsh`, generating zsh completion file: stripe-completion.zsh")
fmt.Println(i18n.T("completion.output.zsh_detected"))
} else {
fmt.Println("Generating zsh completion file: stripe-completion.zsh")
fmt.Println(i18n.T("completion.output.zsh_generating"))
}

err := rootCmd.GenZshCompletionFile("stripe-completion.zsh")
if err == nil {
fmt.Printf("%s%s\n", instructionsHeader, zshCompletionInstructions)
fmt.Printf("%s%s\n", i18n.T("completion.output.instructions_header"), i18n.T("completion.output.zsh_instructions"))
}

return err
Expand All @@ -146,18 +90,18 @@
}

if autoDetected {
fmt.Println("Detected `bash`, generating bash completion file: stripe-completion.bash")
fmt.Println(i18n.T("completion.output.bash_detected"))
} else {
fmt.Println("Generating bash completion file: stripe-completion.bash")
fmt.Println(i18n.T("completion.output.bash_generating"))
}

err := rootCmd.GenBashCompletionFile("stripe-completion.bash")
if err == nil {
switch runtime.GOOS {
case "darwin":
fmt.Printf("%s%s\n", instructionsHeader, bashCompletionInstructionsMac)
fmt.Printf("%s%s\n", i18n.T("completion.output.instructions_header"), i18n.T("completion.output.bash_instructions_mac"))
case "linux":
fmt.Printf("%s%s\n", instructionsHeader, bashCompletionInstructionsLinux)
fmt.Printf("%s%s\n", i18n.T("completion.output.instructions_header"), i18n.T("completion.output.bash_instructions_linux"))
}
}

Expand All @@ -171,15 +115,15 @@
}

if autoDetected {
fmt.Println("Detected `fish`, generating fish completion file: stripe.fish")
fmt.Println(i18n.T("completion.output.fish_detected"))
} else {
fmt.Println("Generating fish completion file: stripe.fish")
fmt.Println(i18n.T("completion.output.fish_generating"))
}

// true enables completion descriptions (fish displays them inline during tab-complete)
err := rootCmd.GenFishCompletionFile("stripe.fish", true)
if err == nil {
fmt.Printf("%s%s\n", instructionsHeader, fishCompletionInstructions)
fmt.Printf("%s%s\n", i18n.T("completion.output.instructions_header"), i18n.T("completion.output.fish_instructions"))
}

return err
Expand Down
22 changes: 10 additions & 12 deletions pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/cobra"

"github.com/stripe/stripe-cli/pkg/config"
"github.com/stripe/stripe-cli/pkg/i18n"
)

type configCmd struct {
Expand All @@ -21,20 +22,17 @@ func newConfigCmd() *configCmd {
config: &Config,
}
cc.cmd = &cobra.Command{
Use: "config",
Short: "Manually change the config values for the CLI",
Long: `config lets you set and unset specific configuration values for your profile if
you need more granular control over the configuration.`,
Example: `stripe config --list
stripe config --set color off
stripe config --unset color`,
RunE: cc.runConfigCmd,
Use: "config",
Short: i18n.T("config.short"),
Long: i18n.T("config.long"),
Example: i18n.T("config.example"),
RunE: cc.runConfigCmd,
}

cc.cmd.Flags().BoolVar(&cc.list, "list", false, "List configs")
cc.cmd.Flags().BoolVarP(&cc.edit, "edit", "e", false, "Open an editor to the config file")
cc.cmd.Flags().StringVar(&cc.unset, "unset", "", "Unset a specific config field")
cc.cmd.Flags().BoolVar(&cc.set, "set", false, "Set a config field to some value")
cc.cmd.Flags().BoolVar(&cc.list, "list", false, i18n.T("config.flags.list"))
cc.cmd.Flags().BoolVarP(&cc.edit, "edit", "e", false, i18n.T("config.flags.edit"))
cc.cmd.Flags().StringVar(&cc.unset, "unset", "", i18n.T("config.flags.unset"))
cc.cmd.Flags().BoolVar(&cc.set, "set", false, i18n.T("config.flags.set"))

cc.cmd.Flags().SetInterspersed(false) // allow args to happen after flags to enable 2 arguments to --set

Expand Down
14 changes: 6 additions & 8 deletions pkg/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/spf13/cobra"

"github.com/stripe/stripe-cli/pkg/config"
"github.com/stripe/stripe-cli/pkg/i18n"
"github.com/stripe/stripe-cli/pkg/rpcservice"
"github.com/stripe/stripe-cli/pkg/stripe"
"github.com/stripe/stripe-cli/pkg/validators"
Expand All @@ -22,17 +23,14 @@ func newDaemonCmd(cfg *config.Config) *daemonCmd {
}

dc.cmd = &cobra.Command{
Use: "daemon",
Args: validators.NoArgs,
Short: "Run as a daemon on your localhost",
Long: `Start a local gRPC server, enabling you to invoke Stripe CLI commands programmatically from a gRPC
client.

Currently, stripe daemon only supports a subset of CLI commands. Documentation is not yet available.`,
Use: "daemon",
Args: validators.NoArgs,
Short: i18n.T("daemon.short"),
Long: i18n.T("daemon.long"),
Run: dc.runDaemonCmd,
Hidden: true,
}
dc.cmd.Flags().IntVar(&dc.port, "port", 0, "The TCP port the daemon will listen to (default: an available port)")
dc.cmd.Flags().IntVar(&dc.port, "port", 0, i18n.T("daemon.flags.port"))

return dc
}
Expand Down
17 changes: 7 additions & 10 deletions pkg/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/stripe/stripe-cli/pkg/i18n"
"github.com/stripe/stripe-cli/pkg/requests"
"github.com/stripe/stripe-cli/pkg/validators"
)
Expand All @@ -25,19 +26,15 @@ func newDeleteCmd(isPreview bool) *requests.Base {

previewNote := ""
if isPreview {
previewNote = "\nThe preview Stripe-Version header is set automatically on all requests.\n"
previewNote = i18n.T("delete.preview_note")
}

reqs.Cmd = &cobra.Command{
Use: "delete <path>",
Args: validators.ExactArgs(1),
Short: "Make a " + verb + " request to the Stripe API",
Long: `Make ` + verb + ` requests to the Stripe API using your test mode key.
` + previewNote + `
For a full list of supported paths, see the API reference:
https://stripe.com/docs/api
`,
Example: `stripe ` + preview + `delete /customers/cus_FROPkgsHVRRspg`,
Use: "delete <path>",
Args: validators.ExactArgs(1),
Short: i18n.Tf("delete.short", i18n.Args{"verb": verb}),
Long: i18n.Tf("delete.long", i18n.Args{"verb": verb, "preview_note": previewNote}),
Example: i18n.Tf("delete.example", i18n.Args{"preview": preview}),
RunE: reqs.RunRequestsCmd,
}

Expand Down
28 changes: 13 additions & 15 deletions pkg/cmd/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@

"github.com/spf13/cobra"

"github.com/stripe/stripe-cli/pkg/i18n"
"github.com/stripe/stripe-cli/pkg/validators"
)

const feedbackAsciiArt = `

Check failure on line 12 in pkg/cmd/feedback.go

View workflow job for this annotation

GitHub Actions / test (1.26.0, ubuntu-latest)

ST1003: const feedbackAsciiArt should be feedbackASCIIArt (staticcheck)

Check failure on line 12 in pkg/cmd/feedback.go

View workflow job for this annotation

GitHub Actions / test (1.26.0, macos-latest)

ST1003: const feedbackAsciiArt should be feedbackASCIIArt (staticcheck)
_ _
___| |_ _ __(_)_ __ ___
/ __| __| '__| | '_ \ / _ \
\__ \ |_| | | | |_) | __/
|___/\__|_| |_| .__/ \___|
|_|
`

type feedbackCmd struct {
cmd *cobra.Command
}
Expand All @@ -17,22 +27,10 @@
cmd: &cobra.Command{
Use: "feedback",
Args: validators.NoArgs,
Short: "Provide us with feedback on the CLI",
Short: i18n.T("feedback.short"),
Run: func(cmd *cobra.Command, args []string) {
output := `
_ _
___| |_ _ __(_)_ __ ___
/ __| __| '__| | '_ \ / _ \
\__ \ |_| | | | |_) | __/
|___/\__|_| |_| .__/ \___|
|_|

We'd love to know what you think of the CLI:

* Report bugs or issues on GitHub: https://github.com/stripe/stripe-cli/issues
`

fmt.Println(output)
fmt.Print(feedbackAsciiArt)
fmt.Println(i18n.T("feedback.output.body"))
},
},
}
Expand Down
Loading
Loading