From 65aad3591732f7de47c9b329053c1ac82660073d Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sat, 17 Jan 2026 21:47:58 +0530 Subject: [PATCH 1/6] Update install command usage --- cli/command/install/install.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/command/install/install.go b/cli/command/install/install.go index 56d3da80..6ad6b06c 100644 --- a/cli/command/install/install.go +++ b/cli/command/install/install.go @@ -34,7 +34,7 @@ func NewInstallCommand(wpmCli command.Cli) *cobra.Command { var opts installOptions cmd := &cobra.Command{ - Use: "install [OPTIONS]", + Use: "install [OPTIONS] [PACKAGE]...", Short: "Install project dependencies and add new packages", Args: cobra.ArbitraryArgs, Example: ` wpm install @@ -131,6 +131,7 @@ func runInstall(ctx context.Context, wpmCli command.Cli, opts installOptions, pa Config: cfg, SaveConfig: configModified, NetworkConcurrency: opts.networkConcurrency, + Trigger: TriggerInstall, }) } From d7e4322de6374ff0e143a3c02871a45018ce799c Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sat, 17 Jan 2026 21:48:08 +0530 Subject: [PATCH 2/6] Add trigger options in runner --- cli/command/install/run.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/cli/command/install/run.go b/cli/command/install/run.go index cc3b7703..1b0c2b25 100644 --- a/cli/command/install/run.go +++ b/cli/command/install/run.go @@ -18,6 +18,14 @@ import ( "github.com/pkg/errors" ) +type Trigger int + +const ( + TriggerUpdate Trigger = iota + TriggerInstall + TriggerUninstall +) + type RunOptions struct { NoDev bool IgnoreScripts bool @@ -25,6 +33,7 @@ type RunOptions struct { Config *wpmjson.Config SaveConfig bool NetworkConcurrency int + Trigger Trigger } func installerProgress(out *output.Output) func(action installer.Action) { @@ -148,10 +157,23 @@ func Run(ctx context.Context, cwd string, wpmCli command.Cli, opts RunOptions) e } // -- Print Summary -- - wpmCli.Output().Prettyln(output.Text{ - Plain: fmt.Sprintf("\n%d %s installed", len(plan), command.Pluralize("package", "s", len(plan))), - Fancy: fmt.Sprintf("\n%s %s installed", aec.GreenF.Apply(strconv.Itoa(len(plan))), command.Pluralize("package", "s", len(plan))), - }) + switch opts.Trigger { + case TriggerInstall: + wpmCli.Output().Prettyln(output.Text{ + Plain: fmt.Sprintf("\n%d %s installed", len(plan), command.Pluralize("package", "s", len(plan))), + Fancy: fmt.Sprintf("\n%s %s installed", aec.GreenF.Apply(strconv.Itoa(len(plan))), command.Pluralize("package", "s", len(plan))), + }) + case TriggerUpdate: + wpmCli.Output().Prettyln(output.Text{ + Plain: fmt.Sprintf("\n%d %s updated", len(plan), command.Pluralize("package", "s", len(plan))), + Fancy: fmt.Sprintf("\n%s %s updated", aec.GreenF.Apply(strconv.Itoa(len(plan))), command.Pluralize("package", "s", len(plan))), + }) + case TriggerUninstall: + wpmCli.Output().Prettyln(output.Text{ + Plain: fmt.Sprintf("\n%d %s uninstalled", len(plan), command.Pluralize("package", "s", len(plan))), + Fancy: fmt.Sprintf("\n%s %s uninstalled", aec.GreenF.Apply(strconv.Itoa(len(plan))), command.Pluralize("package", "s", len(plan))), + }) + } return nil } From b60826a55d46927f7f08a58c325eee05f0561958 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sat, 17 Jan 2026 21:48:17 +0530 Subject: [PATCH 3/6] Add uninstall command --- cli/command/commands/commands.go | 2 + cli/command/uninstall/uninstall.go | 81 ++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 cli/command/uninstall/uninstall.go diff --git a/cli/command/commands/commands.go b/cli/command/commands/commands.go index e61622ad..bd736a9b 100644 --- a/cli/command/commands/commands.go +++ b/cli/command/commands/commands.go @@ -6,6 +6,7 @@ import ( pmInit "wpm/cli/command/init" "wpm/cli/command/install" "wpm/cli/command/publish" + "wpm/cli/command/uninstall" "wpm/cli/command/whoami" "github.com/spf13/cobra" @@ -18,5 +19,6 @@ func AddCommands(cmd *cobra.Command, wpmCli command.Cli) { whoami.NewWhoamiCommand(wpmCli), publish.NewPublishCommand(wpmCli), install.NewInstallCommand(wpmCli), + uninstall.NewUninstallCommand(wpmCli), ) } diff --git a/cli/command/uninstall/uninstall.go b/cli/command/uninstall/uninstall.go new file mode 100644 index 00000000..4aa25f06 --- /dev/null +++ b/cli/command/uninstall/uninstall.go @@ -0,0 +1,81 @@ +package uninstall + +import ( + "context" + "fmt" + "os" + + "wpm/cli" + "wpm/cli/command" + "wpm/cli/command/install" + "wpm/cli/version" + "wpm/pkg/output" + "wpm/pkg/pm/wpmjson" + + "github.com/morikuni/aec" + "github.com/spf13/cobra" +) + +func NewUninstallCommand(wpmCli command.Cli) *cobra.Command { + cmd := &cobra.Command{ + Use: "uninstall [PACKAGE]...", + Short: "Remove dependencies from the project", + Aliases: []string{"remove", "rm"}, + Args: cli.RequiresMinArgs(1), + Example: ` wpm uninstall hello-dolly`, + RunE: func(cmd *cobra.Command, args []string) error { + return runUninstall(cmd.Context(), wpmCli, args) + }, + } + + return cmd +} + +func runUninstall(ctx context.Context, wpmCli command.Cli, packages []string) error { + cwd, err := os.Getwd() + if err != nil { + return err + } + + cfg, err := wpmjson.Read(cwd) + if err != nil { + return err + } + + if cfg == nil { + return fmt.Errorf("No wpm.json, so nothing to remove") + } + + wpmCli.Output().Prettyln(output.Text{ + Plain: "wpm uninstall v" + version.Version, + Fancy: aec.Bold.Apply("wpm uninstall") + " " + aec.LightBlackF.Apply("v"+version.Version), + }) + + changed := false + for _, name := range packages { + if cfg.Dependencies != nil { + if _, ok := (*cfg.Dependencies)[name]; ok { + delete(*cfg.Dependencies, name) + changed = true + } + } + if cfg.DevDependencies != nil { + if _, ok := (*cfg.DevDependencies)[name]; ok { + delete(*cfg.DevDependencies, name) + changed = true + } + } + } + + if !changed { + wpmCli.Out().WriteString("\n") + fmt.Fprintln(wpmCli.Out(), "No matching packages found to uninstall.") + return nil + } + + return install.Run(ctx, cwd, wpmCli, install.RunOptions{ + Config: cfg, + SaveConfig: true, + Trigger: install.TriggerUninstall, + }) +} From cc400739d2cd9c0cff7b0121f724c8589ebdf491 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sat, 17 Jan 2026 22:08:00 +0530 Subject: [PATCH 4/6] Update error message --- cli/command/uninstall/uninstall.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/uninstall/uninstall.go b/cli/command/uninstall/uninstall.go index 4aa25f06..0a461479 100644 --- a/cli/command/uninstall/uninstall.go +++ b/cli/command/uninstall/uninstall.go @@ -43,7 +43,7 @@ func runUninstall(ctx context.Context, wpmCli command.Cli, packages []string) er } if cfg == nil { - return fmt.Errorf("No wpm.json, so nothing to remove") + return fmt.Errorf("no wpm.json found, nothing to uninstall") } wpmCli.Output().Prettyln(output.Text{ From ddd6a82255caa43dcfdba24515e34beb982414e7 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sat, 17 Jan 2026 22:09:18 +0530 Subject: [PATCH 5/6] Remove code duplication --- cli/command/install/run.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/cli/command/install/run.go b/cli/command/install/run.go index 1b0c2b25..63a68247 100644 --- a/cli/command/install/run.go +++ b/cli/command/install/run.go @@ -157,21 +157,20 @@ func Run(ctx context.Context, cwd string, wpmCli command.Cli, opts RunOptions) e } // -- Print Summary -- + var action string switch opts.Trigger { case TriggerInstall: - wpmCli.Output().Prettyln(output.Text{ - Plain: fmt.Sprintf("\n%d %s installed", len(plan), command.Pluralize("package", "s", len(plan))), - Fancy: fmt.Sprintf("\n%s %s installed", aec.GreenF.Apply(strconv.Itoa(len(plan))), command.Pluralize("package", "s", len(plan))), - }) + action = "installed" case TriggerUpdate: - wpmCli.Output().Prettyln(output.Text{ - Plain: fmt.Sprintf("\n%d %s updated", len(plan), command.Pluralize("package", "s", len(plan))), - Fancy: fmt.Sprintf("\n%s %s updated", aec.GreenF.Apply(strconv.Itoa(len(plan))), command.Pluralize("package", "s", len(plan))), - }) + action = "updated" case TriggerUninstall: + action = "uninstalled" + } + + if action != "" { wpmCli.Output().Prettyln(output.Text{ - Plain: fmt.Sprintf("\n%d %s uninstalled", len(plan), command.Pluralize("package", "s", len(plan))), - Fancy: fmt.Sprintf("\n%s %s uninstalled", aec.GreenF.Apply(strconv.Itoa(len(plan))), command.Pluralize("package", "s", len(plan))), + Plain: fmt.Sprintf("\n%d %s %s", len(plan), command.Pluralize("package", "s", len(plan)), action), + Fancy: fmt.Sprintf("\n%s %s %s", aec.GreenF.Apply(strconv.Itoa(len(plan))), command.Pluralize("package", "s", len(plan)), action), }) } From 27b5d8d15d35c7ce1d447586319312a4bbedc162 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sat, 17 Jan 2026 22:10:01 +0530 Subject: [PATCH 6/6] Fix typo --- cli/command/uninstall/uninstall.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/uninstall/uninstall.go b/cli/command/uninstall/uninstall.go index 0a461479..8631fec9 100644 --- a/cli/command/uninstall/uninstall.go +++ b/cli/command/uninstall/uninstall.go @@ -43,7 +43,7 @@ func runUninstall(ctx context.Context, wpmCli command.Cli, packages []string) er } if cfg == nil { - return fmt.Errorf("no wpm.json found, nothing to uninstall") + return fmt.Errorf("no wpm.json found, so nothing to uninstall") } wpmCli.Output().Prettyln(output.Text{