Repository navigation
Add uninstall command #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
65aad35
Update install command usage
thelovekesh d7e4322
Add trigger options in runner
thelovekesh b60826a
Add uninstall command
thelovekesh cc40073
Update error message
thelovekesh ddd6a82
Remove code duplication
thelovekesh 27b5d8d
Fix typo
thelovekesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,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") | ||
| } | ||
|
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, | ||
| }) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.