-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support awareness of installed plugins * suppress telemetry for plugin commands plugins will handle sending their own telemetry for now * trace install reqs; don't set opaque URL on redirect * improve plugin install outputs * lint * lint: the sequel * SyncConfig back to pkg level public method * migrate installed plugins getter to profile * migrate IsPluginCommand to plugins pkg
- Loading branch information
1 parent
d0cc5bb
commit 035c6f5
Showing
12 changed files
with
247 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/stripe/stripe-cli/pkg/config" | ||
"github.com/stripe/stripe-cli/pkg/plugins" | ||
"github.com/stripe/stripe-cli/pkg/validators" | ||
) | ||
|
||
type pluginTemplateCmd struct { | ||
cfg *config.Config | ||
cmd *cobra.Command | ||
fs afero.Fs | ||
} | ||
|
||
// newPluginTemplateCmd is a generic plugin command template to dynamically use | ||
// so that we can add any locally installed plugins as supported commands in the CLI | ||
func newPluginTemplateCmd(config *config.Config, plugin *plugins.Plugin) *pluginTemplateCmd { | ||
ptc := &pluginTemplateCmd{} | ||
ptc.fs = afero.NewOsFs() | ||
ptc.cfg = config | ||
|
||
ptc.cmd = &cobra.Command{ | ||
Use: plugin.Shortname, | ||
Short: plugin.Shortdesc, | ||
RunE: ptc.runPluginCmd, | ||
Annotations: map[string]string{"scope": "plugin"}, | ||
} | ||
|
||
// override the CLI's help command and let the plugin supply the help text instead | ||
ptc.cmd.SetHelpCommand(&cobra.Command{ | ||
Use: "no-help", | ||
Hidden: true, | ||
}) | ||
|
||
return ptc | ||
} | ||
|
||
// runPluginCmd hands off to the plugin itself to take over | ||
func (ptc *pluginTemplateCmd) runPluginCmd(cmd *cobra.Command, args []string) error { | ||
ctx := withSIGTERMCancel(cmd.Context(), func() { | ||
log.WithFields(log.Fields{ | ||
"prefix": "cmd.pluginCmd.runPluginCmd", | ||
}).Debug("Ctrl+C received, cleaning up...") | ||
}) | ||
|
||
fs := afero.NewOsFs() | ||
plugin, err := plugins.LookUpPlugin(ctx, ptc.cfg, fs, cmd.CalledAs()) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
err = plugin.Run(ctx, ptc.cfg, fs, args) | ||
plugins.CleanupAllClients() | ||
|
||
if err != nil { | ||
if err == validators.ErrAPIKeyNotConfigured { | ||
return errors.New("Install failed due to API key not configured. Please run `stripe login` or specify the `--api-key`") | ||
} | ||
|
||
log.WithFields(log.Fields{ | ||
"prefix": "pluginTemplateCmd.runPluginCmd", | ||
}).Debug(fmt.Sprintf("Plugin command '%s' exited with error: %s", plugin.Shortname, err)) | ||
} | ||
|
||
return nil | ||
} |
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
Oops, something went wrong.