Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/command/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -18,5 +19,6 @@ func AddCommands(cmd *cobra.Command, wpmCli command.Cli) {
whoami.NewWhoamiCommand(wpmCli),
publish.NewPublishCommand(wpmCli),
install.NewInstallCommand(wpmCli),
uninstall.NewUninstallCommand(wpmCli),
)
}
3 changes: 2 additions & 1 deletion cli/command/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -131,6 +131,7 @@ func runInstall(ctx context.Context, wpmCli command.Cli, opts installOptions, pa
Config: cfg,
SaveConfig: configModified,
NetworkConcurrency: opts.networkConcurrency,
Trigger: TriggerInstall,
})
}

Expand Down
29 changes: 25 additions & 4 deletions cli/command/install/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ import (
"github.com/pkg/errors"
)

type Trigger int

const (
TriggerUpdate Trigger = iota
TriggerInstall
TriggerUninstall
)

type RunOptions struct {
NoDev bool
IgnoreScripts bool
DryRun bool
Config *wpmjson.Config
SaveConfig bool
NetworkConcurrency int
Trigger Trigger
}

func installerProgress(out *output.Output) func(action installer.Action) {
Expand Down Expand Up @@ -148,10 +157,22 @@ 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))),
})
var action string
switch opts.Trigger {
case TriggerInstall:
action = "installed"
case TriggerUpdate:
action = "updated"
case TriggerUninstall:
action = "uninstalled"
}

if action != "" {
wpmCli.Output().Prettyln(output.Text{
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),
})
}
Comment thread
thelovekesh marked this conversation as resolved.
Resolved

return nil
}
81 changes: 81 additions & 0 deletions cli/command/uninstall/uninstall.go
Original file line number Diff line number Diff line change
@@ -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 found, so nothing to uninstall")
}
Comment thread
thelovekesh marked this conversation as resolved.
Resolved

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,
})
}