-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
110 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"golang.org/x/crypto/ssh/terminal" | ||
|
||
"github.com/stripe/stripe-cli/pkg/ansi" | ||
) | ||
|
||
func init() { | ||
cobra.AddTemplateFunc("wrappedInheritedFlagUsages", wrappedInheritedFlagUsages) | ||
cobra.AddTemplateFunc("wrappedLocalFlagUsages", wrappedLocalFlagUsages) | ||
} | ||
|
||
func getBanner() string { | ||
return ansi.Italic("⚠️ The Stripe CLI is in beta! Share your feedback with `stripe feedback` ⚠️") | ||
} | ||
|
||
func getUsageTemplate() string { | ||
return fmt.Sprintf(`%s{{if .Runnable}} | ||
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}} | ||
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}} | ||
%s | ||
{{.NameAndAliases}}{{end}}{{if .HasExample}} | ||
%s | ||
{{.Example}}{{end}}{{if .HasAvailableSubCommands}}{{if .Annotations}} | ||
%s{{range $index, $cmd := .Commands}}{{if (eq (index $.Annotations $cmd.Name) "http")}} | ||
{{rpad $cmd.Name $cmd.NamePadding }} {{$cmd.Short}}{{end}}{{end}} | ||
%s{{range $index, $cmd := .Commands}}{{if (eq (index $.Annotations $cmd.Name) "webhooks")}} | ||
{{rpad $cmd.Name $cmd.NamePadding }} {{$cmd.Short}}{{end}}{{end}} | ||
%s{{range $index, $cmd := .Commands}}{{if (eq (index $.Annotations $cmd.Name) "stripe")}} | ||
{{rpad $cmd.Name $cmd.NamePadding }} {{$cmd.Short}}{{end}}{{end}} | ||
%s{{range $index, $cmd := .Commands}}{{if (not (index $.Annotations $cmd.Name))}} | ||
{{rpad $cmd.Name $cmd.NamePadding }} {{$cmd.Short}}{{end}}{{end}}{{else}} | ||
%s{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}} | ||
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} | ||
%s | ||
{{wrappedLocalFlagUsages . | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}} | ||
%s | ||
{{wrappedInheritedFlagUsages . | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}} | ||
%s{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}} | ||
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}} | ||
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}} | ||
`, | ||
ansi.Bold("Usage:"), | ||
ansi.Bold("Aliases:"), | ||
ansi.Bold("Examples:"), | ||
ansi.Bold("HTTP commands:"), | ||
ansi.Bold("Webhook commands:"), | ||
ansi.Bold("Stripe commands:"), | ||
ansi.Bold("Other commands:"), | ||
ansi.Bold("Available commands:"), | ||
ansi.Bold("Flags:"), | ||
ansi.Bold("Global flags:"), | ||
ansi.Bold("Additional help topics:"), | ||
) | ||
} | ||
|
||
func getTerminalWidth() int { | ||
var width int | ||
width, _, err := terminal.GetSize(0) | ||
if err != nil { | ||
width = 80 | ||
} | ||
return width | ||
} | ||
|
||
func wrappedInheritedFlagUsages(cmd *cobra.Command) string { | ||
return cmd.InheritedFlags().FlagUsagesWrapped(getTerminalWidth()) | ||
} | ||
|
||
func wrappedLocalFlagUsages(cmd *cobra.Command) string { | ||
return cmd.LocalFlags().FlagUsagesWrapped(getTerminalWidth()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters