Skip to content

Commit

Permalink
Add api-base flag to plugin commands (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcheung-stripe committed Sep 22, 2022
1 parent af04d45 commit 45b1ba0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions pkg/cmd/plugin/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type InstallCmd struct {
archiveURL string
archivePath string
localPluginDir string

apiBaseURL string
}

// NewInstallCmd creates a command for installing plugins
Expand All @@ -51,6 +53,10 @@ func NewInstallCmd(config *config.Config) *InstallCmd {
ic.Cmd.Flags().StringVar(&ic.localPluginDir, "local", "", "Install a development version plugin from a local development folder")
ic.Cmd.Flags().Bool("archive", false, "Install a plugin by archive data from stdout")

// Hidden configuration flags, useful for dev/debugging
ic.Cmd.Flags().StringVar(&ic.apiBaseURL, "api-base", stripe.DefaultAPIBaseURL, "Sets the API base URL")
ic.Cmd.Flags().MarkHidden("api-base") // #nosec G104

return ic
}

Expand Down Expand Up @@ -92,7 +98,7 @@ func (ic *InstallCmd) installPluginByName(cmd *cobra.Command, arg string) error
}).Debug("Ctrl+C received, cleaning up...")
})

err = plugin.Install(ctx, ic.cfg, ic.fs, version, stripe.DefaultAPIBaseURL)
err = plugin.Install(ctx, ic.cfg, ic.fs, version, ic.apiBaseURL)

return err
}
Expand Down Expand Up @@ -155,7 +161,7 @@ func (ic *InstallCmd) runInstallCmd(cmd *cobra.Command, args []string) error {
}
} else {
// Refresh the plugin before proceeding
err = plugins.RefreshPluginManifest(cmd.Context(), ic.cfg, ic.fs, stripe.DefaultAPIBaseURL)
err = plugins.RefreshPluginManifest(cmd.Context(), ic.cfg, ic.fs, ic.apiBaseURL)
if err != nil {
return err
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/cmd/plugin/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type UpgradeCmd struct {
cfg *config.Config
Cmd *cobra.Command
fs afero.Fs

apiBaseURL string
}

// NewUpgradeCmd creates a new command for upgrading plugins
Expand All @@ -36,6 +38,10 @@ func NewUpgradeCmd(config *config.Config) *UpgradeCmd {
RunE: uc.runUpgradeCmd,
}

// Hidden configuration flags, useful for dev/debugging
uc.Cmd.Flags().StringVar(&uc.apiBaseURL, "api-base", stripe.DefaultAPIBaseURL, "Sets the API base URL")
uc.Cmd.Flags().MarkHidden("api-base") // #nosec G104

return uc
}

Expand All @@ -47,7 +53,7 @@ func (uc *UpgradeCmd) runUpgradeCmd(cmd *cobra.Command, args []string) error {
})

// Refresh the plugin info before proceeding
plugins.RefreshPluginManifest(cmd.Context(), uc.cfg, uc.fs, stripe.DefaultAPIBaseURL)
plugins.RefreshPluginManifest(cmd.Context(), uc.cfg, uc.fs, uc.apiBaseURL)

plugin, err := plugins.LookUpPlugin(cmd.Context(), uc.cfg, uc.fs, args[0])

Expand All @@ -57,7 +63,7 @@ func (uc *UpgradeCmd) runUpgradeCmd(cmd *cobra.Command, args []string) error {

version := plugin.LookUpLatestVersion()

err = plugin.Install(ctx, uc.cfg, uc.fs, version, stripe.DefaultAPIBaseURL)
err = plugin.Install(ctx, uc.cfg, uc.fs, version, uc.apiBaseURL)

if err == nil {
color := ansi.Color(os.Stdout)
Expand Down

0 comments on commit 45b1ba0

Please sign in to comment.