|
| 1 | +/* |
| 2 | +Copyright © 2024 jaronnie <jaron@jaronnie.com> |
| 3 | +
|
| 4 | +*/ |
| 5 | + |
| 6 | +package plugin |
| 7 | + |
| 8 | +import ( |
| 9 | + "github.com/spf13/cobra" |
| 10 | + |
| 11 | + "github.com/jzero-io/jzero/cmd/jzero/internal/command/plugin/pluginlist" |
| 12 | + "github.com/jzero-io/jzero/cmd/jzero/internal/command/plugin/pluginremove" |
| 13 | +) |
| 14 | + |
| 15 | +var ( |
| 16 | + // ValidPluginFilenamePrefixes defines the allowed plugin prefix to search |
| 17 | + ValidPluginFilenamePrefixes = []string{"jzero"} |
| 18 | +) |
| 19 | + |
| 20 | +// pluginCmd represents the plugin command |
| 21 | +var pluginCmd = &cobra.Command{ |
| 22 | + Use: "plugin", |
| 23 | + Short: "Manage jzero plugins", |
| 24 | + Long: `Provides utilities for interacting with plugins. |
| 25 | +Plugins provide extended functionality that is not part of the major command-line distribution. |
| 26 | +Plugins must be prefixed with "jzero-" and are stored in ~/.jzero/plugins.`, |
| 27 | +} |
| 28 | + |
| 29 | +var pluginListCmd = &cobra.Command{ |
| 30 | + Use: "list", |
| 31 | + Short: "List all installed jzero plugins", |
| 32 | + Long: `List all installed plugins from ~/.jzero/plugins directory. |
| 33 | +Plugins must be prefixed with "jzero-" to be recognized.`, |
| 34 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 35 | + return pluginlist.Run() |
| 36 | + }, |
| 37 | +} |
| 38 | + |
| 39 | +var pluginRemoveCmd = &cobra.Command{ |
| 40 | + Use: "remove <plugin-name>", |
| 41 | + Short: "Remove an installed jzero plugin", |
| 42 | + Long: `Remove an installed jzero plugin from ~/.jzero/plugins. |
| 43 | +
|
| 44 | +Example: |
| 45 | + jzero plugin remove jzero-myplugin`, |
| 46 | + Args: cobra.ExactArgs(1), |
| 47 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 48 | + return pluginremove.Run(args[0]) |
| 49 | + }, |
| 50 | +} |
| 51 | + |
| 52 | +func GetCommand() *cobra.Command { |
| 53 | + pluginCmd.AddCommand(pluginListCmd) |
| 54 | + pluginCmd.AddCommand(pluginRemoveCmd) |
| 55 | + |
| 56 | + pluginListCmd.Flags().BoolVar(&pluginlist.NameOnly, "name-only", false, "If true, display only the binary name of each plugin, rather than its full path") |
| 57 | + pluginRemoveCmd.Flags().BoolVar(&pluginremove.Force, "force", false, "Force removal without confirmation") |
| 58 | + |
| 59 | + return pluginCmd |
| 60 | +} |
0 commit comments