|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "flag" |
| 6 | + "fmt" |
| 7 | + "io" |
| 8 | + "os" |
| 9 | + "path/filepath" |
| 10 | + |
| 11 | + pluginbundle "codemap/plugins" |
| 12 | +) |
| 13 | + |
| 14 | +// RunPlugin handles the "codemap plugin" subcommand. |
| 15 | +func RunPlugin(args []string) { |
| 16 | + subCmd := "" |
| 17 | + if len(args) > 0 { |
| 18 | + subCmd = args[0] |
| 19 | + } |
| 20 | + |
| 21 | + switch subCmd { |
| 22 | + case "install": |
| 23 | + runPluginInstall(args[1:]) |
| 24 | + default: |
| 25 | + fmt.Println("Usage: codemap plugin install") |
| 26 | + fmt.Println() |
| 27 | + fmt.Println("Commands:") |
| 28 | + fmt.Println(" install Install the Codemap plugin into ~/.agents/plugins and ~/plugins") |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +func runPluginInstall(args []string) { |
| 33 | + fs := flag.NewFlagSet("plugin install", flag.ContinueOnError) |
| 34 | + fs.SetOutput(io.Discard) |
| 35 | + homeDir := fs.String("home", "", "Override the home directory used for plugin installation") |
| 36 | + pluginPath := fs.String("plugin-path", "", "Override the installed plugin path") |
| 37 | + marketplacePath := fs.String("marketplace-path", "", "Override the marketplace manifest path") |
| 38 | + if err := fs.Parse(args); err != nil { |
| 39 | + if errors.Is(err, flag.ErrHelp) { |
| 40 | + fmt.Println("Usage: codemap plugin install [--home <dir>] [--plugin-path <dir>] [--marketplace-path <file>]") |
| 41 | + return |
| 42 | + } |
| 43 | + fmt.Fprintf(os.Stderr, "Error: %v\n", err) |
| 44 | + fmt.Fprintln(os.Stderr, "Usage: codemap plugin install [--home <dir>] [--plugin-path <dir>] [--marketplace-path <file>]") |
| 45 | + os.Exit(2) |
| 46 | + } |
| 47 | + if fs.NArg() != 0 { |
| 48 | + fmt.Fprintln(os.Stderr, "Usage: codemap plugin install [--home <dir>] [--plugin-path <dir>] [--marketplace-path <file>]") |
| 49 | + os.Exit(1) |
| 50 | + } |
| 51 | + |
| 52 | + result, err := pluginbundle.InstallCodemapPlugin(pluginbundle.InstallOptions{ |
| 53 | + HomeDir: *homeDir, |
| 54 | + PluginPath: *pluginPath, |
| 55 | + MarketplacePath: *marketplacePath, |
| 56 | + }) |
| 57 | + if err != nil { |
| 58 | + fmt.Fprintf(os.Stderr, "Plugin install failed: %v\n", err) |
| 59 | + os.Exit(1) |
| 60 | + } |
| 61 | + |
| 62 | + absPluginPath, _ := filepath.Abs(result.PluginPath) |
| 63 | + absMarketplacePath, _ := filepath.Abs(result.MarketplacePath) |
| 64 | + |
| 65 | + fmt.Println("codemap plugin install") |
| 66 | + fmt.Printf("Plugin: %s\n", absPluginPath) |
| 67 | + fmt.Printf("Marketplace: %s\n", absMarketplacePath) |
| 68 | + fmt.Printf("Files written: %d\n", result.FilesWritten) |
| 69 | + if result.FilesUnchanged > 0 { |
| 70 | + fmt.Printf("Files unchanged: %d\n", result.FilesUnchanged) |
| 71 | + } |
| 72 | + switch { |
| 73 | + case result.CreatedMarketplace: |
| 74 | + fmt.Println("Marketplace entry: created") |
| 75 | + case result.UpdatedMarketplace: |
| 76 | + fmt.Println("Marketplace entry: updated") |
| 77 | + default: |
| 78 | + fmt.Println("Marketplace entry: already configured") |
| 79 | + } |
| 80 | + fmt.Println() |
| 81 | + fmt.Println("Next:") |
| 82 | + fmt.Println(" 1. Restart Codex or reload plugins.") |
| 83 | + fmt.Println(" 2. Verify the Codemap plugin appears in your plugin list.") |
| 84 | + fmt.Println(" 3. If Codemap was installed before this release, update it so `codemap mcp` is available.") |
| 85 | +} |
0 commit comments