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 @@ -96,6 +96,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/match v1.2.0 // indirect
golang.org/x/text v0.34.0 // indirect
golang.org/x/text v0.34.0
gopkg.in/warnings.v0 v0.1.2 // indirect
)
16 changes: 12 additions & 4 deletions pkg/plugins/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"time"

"golang.org/x/term"
"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/stripe/stripe-cli/pkg/ansi"
"github.com/stripe/stripe-cli/pkg/config"
Expand Down Expand Up @@ -66,6 +68,12 @@ type Release struct {
Runtime map[string]string `toml:"Runtime,omitempty"`
}

// GetDisplayName returns a human-friendly display name derived from the plugin's Shortname,
// e.g. "projects" → "Stripe Projects".
func (p *Plugin) GetDisplayName() string {
return "Stripe " + cases.Title(language.English).String(p.Shortname)
}

// getPluginInterface computes the correct metadata needed for starting the hcplugin client
func (p *Plugin) getPluginInterface() (hcplugin.HandshakeConfig, map[int]hcplugin.PluginSet) {
handshakeConfig := hcplugin.HandshakeConfig{
Expand Down Expand Up @@ -189,14 +197,14 @@ func (p *Plugin) getReleaseForVersion(version string) *Release {

// Install installs the plugin of the given version
func (p *Plugin) Install(ctx context.Context, cfg config.IConfig, fs afero.Fs, version string, baseURL string) error {
spinner := ansi.StartNewSpinner(ansi.Faint(fmt.Sprintf("installing '%s' v%s...", p.Shortname, version)), os.Stdout)
spinner := ansi.StartNewSpinner(ansi.Faint(fmt.Sprintf("installing \"%s\" v%s...", p.GetDisplayName(), version)), os.Stdout)

apiKey, _ := cfg.GetProfile().GetAPIKey(false)

pluginData, err := requests.GetPluginData(ctx, baseURL, stripe.APIVersion, apiKey, cfg.GetProfile())

if err != nil {
ansi.StopSpinner(spinner, ansi.Faint(fmt.Sprintf("could not install plugin '%s'", p.Shortname)), os.Stdout)
ansi.StopSpinner(spinner, ansi.Faint(fmt.Sprintf("could not install plugin \"%s\"", p.GetDisplayName())), os.Stdout)

log.WithFields(log.Fields{
"prefix": "plugins.plugin.Install",
Expand All @@ -213,7 +221,7 @@ func (p *Plugin) Install(ctx context.Context, cfg config.IConfig, fs afero.Fs, v
if err := InstallNodeRuntime(ctx, cfg, fs, nodeVersion); err != nil {
return fmt.Errorf("failed to install required Node.js runtime: %w", err)
}
spinner = ansi.StartNewSpinner(ansi.Faint(fmt.Sprintf("installing '%s' v%s...", p.Shortname, version)), os.Stdout)
spinner = ansi.StartNewSpinner(ansi.Faint(fmt.Sprintf("installing \"%s\" v%s...", p.GetDisplayName(), version)), os.Stdout)
}
}

Expand All @@ -223,7 +231,7 @@ func (p *Plugin) Install(ctx context.Context, cfg config.IConfig, fs afero.Fs, v
err = p.downloadAndSavePlugin(cfg, pluginDownloadURL, fs, version)

if err != nil {
ansi.StopSpinner(spinner, ansi.Faint(fmt.Sprintf("could not install plugin '%s': %s", p.Shortname, err)), os.Stdout)
ansi.StopSpinner(spinner, ansi.Faint(fmt.Sprintf("could not install plugin \"%s\": %s", p.GetDisplayName(), err)), os.Stdout)
return err
}

Expand Down
Loading