-
-
Notifications
You must be signed in to change notification settings - Fork 3
Add dist-tag command
#256
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
Add dist-tag command
#256
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b8355e0
Add client method to set dist tag
thelovekesh e23fd06
Update dist tag autocomp func
thelovekesh 3827b79
Add dist tag command
thelovekesh 1d47153
Add dist tag command docs
thelovekesh 6b35fdd
Add dist-tag add sub command
thelovekesh 95b2398
Add dist-tag add subcommand docs
thelovekesh 9bab4ae
Update AddDistTag func comment
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package disttag | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "go.wpm.so/cli/cli" | ||
| "go.wpm.so/cli/cli/command" | ||
| "go.wpm.so/cli/cli/command/completion" | ||
| "go.wpm.so/cli/pkg/pm/wpmjson/validator" | ||
| ) | ||
|
|
||
| const defaultDistTag = "latest" | ||
|
|
||
| func newAddCommand(wpmCli command.Cli) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "add PACKAGE@VERSION [TAG]", | ||
| Short: "Point a dist tag at a package version", | ||
| Args: cli.RequiresRangeArgs(1, 2), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return runAdd(cmd.Context(), wpmCli, args) | ||
| }, | ||
| ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
| if len(args) == 1 { | ||
| return completion.DistTags()(cmd, args, toComplete) | ||
| } | ||
| return nil, cobra.ShellCompDirectiveNoFileComp | ||
| }, | ||
| } | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runAdd(ctx context.Context, wpmCli command.Cli, args []string) error { | ||
| name, version, err := parsePackageVersion(args[0]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| tag := defaultDistTag | ||
| if len(args) == 2 { | ||
| tag = args[1] | ||
| } | ||
|
|
||
| if err := validator.IsValidDistTag(tag); err != nil { | ||
| return fmt.Errorf("invalid dist tag %q: %w", tag, err) | ||
| } | ||
|
|
||
| if err := validateAuth(wpmCli); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| client, err := wpmCli.RegistryClient() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := wpmCli.Progress().RunWithProgress( | ||
| "", | ||
| func() error { return client.AddDistTag(ctx, name, tag, version) }, | ||
| wpmCli.Err(), | ||
| ); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| wpmCli.Out().WriteString(fmt.Sprintf("+%s: %s@%s\n", tag, name, version)) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func validateAuth(wpmCli command.Cli) error { | ||
| cfg := wpmCli.ConfigFile() | ||
| if cfg.DefaultUser == "" || cfg.AuthToken == "" { | ||
| return errors.New("user must be logged in to perform this action") | ||
| } | ||
| return nil | ||
| } | ||
|
thelovekesh marked this conversation as resolved.
|
||
|
|
||
| func parsePackageVersion(arg string) (name, version string, err error) { | ||
| lastAt := strings.LastIndex(arg, "@") | ||
| if lastAt <= 0 { | ||
| return "", "", fmt.Errorf("invalid package spec %q: expected <pkg>@<version>", arg) | ||
| } | ||
|
|
||
| name = arg[:lastAt] | ||
| version = arg[lastAt+1:] | ||
|
|
||
| if err := validator.IsValidPackageName(name); err != nil { | ||
| return "", "", fmt.Errorf("invalid package name %q: %w", name, err) | ||
| } | ||
|
|
||
| if err := validator.IsValidVersion(version); err != nil { | ||
| return "", "", fmt.Errorf("invalid version %q: %w", version, err) | ||
| } | ||
|
|
||
| return name, version, nil | ||
| } | ||
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,26 @@ | ||
| package disttag | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "go.wpm.so/cli/cli" | ||
| "go.wpm.so/cli/cli/command" | ||
| ) | ||
|
|
||
| func NewDistTagCommand(wpmCli command.Cli) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "dist-tag", | ||
| Short: "Manage package distribution tags", | ||
| Aliases: []string{"dist-tags"}, | ||
| Args: cli.NoArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| cmd.SetOut(wpmCli.Out()) | ||
| cmd.HelpFunc()(cmd, args) | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| cmd.AddCommand(newAddCommand(wpmCli)) | ||
|
|
||
| return cmd | ||
| } |
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,33 @@ | ||
| # wpm dist-tag | ||
|
|
||
| <!-- prettier-ignore-start --> | ||
| <!---MARKER_GEN_START--> | ||
| Manage package distribution tags | ||
|
|
||
| ### Aliases | ||
|
|
||
| `wpm dist-tag`, `wpm dist-tags` | ||
|
|
||
| ### Subcommands | ||
|
|
||
| | Name | Description | | ||
| |:-------------------------|:--------------------------------------| | ||
| | [`add`](dist-tag_add.md) | Point a dist tag at a package version | | ||
|
|
||
|
|
||
|
|
||
| <!---MARKER_GEN_END--> | ||
| <!-- prettier-ignore-end --> | ||
|
|
||
| ## Description | ||
|
|
||
| `wpm dist-tag` groups the subcommands that manage a package's distribution tags. | ||
|
|
||
| A distribution tag is a human-friendly label, such as `latest` or `beta`, that | ||
| points at a specific published version. Tags give consumers a stable name to | ||
| install against instead of pinning an exact version: `wpm install acme-blocks` | ||
| resolves through the `latest` tag to whatever version it currently points at. | ||
|
|
||
| The `latest` tag is special and it is what `wpm install <pkg>` uses when no | ||
| version or tag is requested. Any other tag (`beta`, `next`, `canary`, …) is a | ||
| convention you define for your own release workflow. |
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,45 @@ | ||
| # wpm dist-tag add | ||
|
|
||
| <!-- prettier-ignore-start --> | ||
| <!---MARKER_GEN_START--> | ||
| Point a dist tag at a package version | ||
|
|
||
|
|
||
| <!---MARKER_GEN_END--> | ||
| <!-- prettier-ignore-end --> | ||
|
|
||
| ## Description | ||
|
|
||
| Point a distribution tag at an already-published version of a package. | ||
|
|
||
| The spec is `<pkg>@<version>`, where the version must be a concrete semantic | ||
| version that already exists in the registry and the tag always resolves to an | ||
| exact release, never to another tag. If you omit the tag, it defaults to | ||
| `latest`. | ||
|
|
||
| You must be logged in (`wpm auth login`) or have `WPM_TOKEN` set, and you need | ||
| write access to the package. On success wpm prints a one-line summary: | ||
|
|
||
| ```console | ||
| $ wpm dist-tag add acme-blocks@1.4.0 beta | ||
| +beta: acme-blocks@1.4.0 | ||
| ``` | ||
|
|
||
| Moving an existing tag is the same operation as creating one: re-run `add` with | ||
| a different version and the tag is re-pointed. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Tag a version as `latest` | ||
|
|
||
| ```console | ||
| $ wpm dist-tag add acme-blocks@1.4.0 | ||
| +latest: acme-blocks@1.4.0 | ||
| ``` | ||
|
|
||
| ### Create a pre-release tag | ||
|
|
||
| ```console | ||
| $ wpm dist-tag add acme-blocks@2.0.0-beta.1 beta | ||
| +beta: acme-blocks@2.0.0-beta.1 | ||
| ``` |
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
Oops, something went wrong.
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.