-
Notifications
You must be signed in to change notification settings - Fork 84
Add tags commands #555
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
Open
mikesellitto
wants to merge
5
commits into
master
Choose a base branch
from
mike/tags
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add tags commands #555
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c430c25
Add `PatchRequest` HTTP helper
mikesellitto 6dcd389
Add tag model and parser
mikesellitto 531ed39
Add tag API client functions
mikesellitto 60a0e43
Add tag printers
mikesellitto fe6497b
Add `tags` command for managing workplace tags
mikesellitto 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| /* | ||
| Copyright © 2026 Doppler <support@doppler.com> | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/DopplerHQ/cli/pkg/configuration" | ||
| "github.com/DopplerHQ/cli/pkg/controllers" | ||
| "github.com/DopplerHQ/cli/pkg/http" | ||
| "github.com/DopplerHQ/cli/pkg/printer" | ||
| "github.com/DopplerHQ/cli/pkg/utils" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var validTagColors = []string{"gray", "purple", "blue", "green", "yellow", "orange", "red", "pink"} | ||
| var validTagColorsList = strings.Join(validTagColors, ", ") | ||
|
|
||
| var tagsCmd = &cobra.Command{ | ||
| Use: "tags", | ||
| Short: "Manage workplace tags", | ||
| Args: cobra.NoArgs, | ||
| Run: tags, | ||
| } | ||
|
|
||
| var tagsGetCmd = &cobra.Command{ | ||
| Use: "get [slug]", | ||
| Short: "Get info for a tag", | ||
| Args: cobra.ExactArgs(1), | ||
| ValidArgsFunction: tagSlugsValidArgs, | ||
| Run: getTag, | ||
| } | ||
|
|
||
| var tagsCreateCmd = &cobra.Command{ | ||
| Use: "create [name]", | ||
| Short: "Create a tag", | ||
| Args: cobra.ExactArgs(1), | ||
| Run: createTag, | ||
| } | ||
|
|
||
| var tagsUpdateCmd = &cobra.Command{ | ||
| Use: "update [slug]", | ||
| Short: "Update a tag", | ||
| Args: func(cmd *cobra.Command, args []string) error { | ||
| if err := cobra.ExactArgs(1)(cmd, args); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if cmd.Flag("name").Value.String() == "" && cmd.Flag("color").Value.String() == "" { | ||
| return errors.New("command needs flag --name or --color") | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| ValidArgsFunction: tagSlugsValidArgs, | ||
| Run: updateTag, | ||
| } | ||
|
|
||
| var tagsDeleteCmd = &cobra.Command{ | ||
| Use: "delete [slug]", | ||
| Short: "Delete a tag", | ||
| Args: cobra.ExactArgs(1), | ||
| ValidArgsFunction: tagSlugsValidArgs, | ||
| Run: deleteTag, | ||
| } | ||
|
|
||
| func tags(cmd *cobra.Command, args []string) { | ||
| jsonFlag := utils.OutputJSON | ||
| localConfig := configuration.LocalConfig(cmd) | ||
|
|
||
| utils.RequireValue("token", localConfig.Token.Value) | ||
|
|
||
| info, err := http.GetTags(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value) | ||
| if !err.IsNil() { | ||
| utils.HandleError(err.Unwrap(), err.Message) | ||
| } | ||
|
|
||
| printer.TagsInfo(info, jsonFlag) | ||
| } | ||
|
|
||
| func getTag(cmd *cobra.Command, args []string) { | ||
| jsonFlag := utils.OutputJSON | ||
| localConfig := configuration.LocalConfig(cmd) | ||
|
|
||
| slug := args[0] | ||
|
|
||
| utils.RequireValue("token", localConfig.Token.Value) | ||
| utils.RequireValue("slug", slug) | ||
|
|
||
| info, err := http.GetTag(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, slug) | ||
| if !err.IsNil() { | ||
| utils.HandleError(err.Unwrap(), err.Message) | ||
| } | ||
|
|
||
| printer.TagInfo(info, jsonFlag) | ||
| } | ||
|
|
||
| func createTag(cmd *cobra.Command, args []string) { | ||
| jsonFlag := utils.OutputJSON | ||
| color := cmd.Flag("color").Value.String() | ||
| slug := cmd.Flag("slug").Value.String() | ||
| localConfig := configuration.LocalConfig(cmd) | ||
|
|
||
| name := args[0] | ||
|
|
||
| utils.RequireValue("token", localConfig.Token.Value) | ||
| utils.RequireValue("name", name) | ||
|
|
||
| info, err := http.CreateTag(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, name, color, slug) | ||
| if !err.IsNil() { | ||
| utils.HandleError(err.Unwrap(), err.Message) | ||
| } | ||
|
|
||
| if !utils.Silent { | ||
| printer.TagInfo(info, jsonFlag) | ||
| } | ||
| } | ||
|
|
||
| func updateTag(cmd *cobra.Command, args []string) { | ||
| jsonFlag := utils.OutputJSON | ||
| name := cmd.Flag("name").Value.String() | ||
| color := cmd.Flag("color").Value.String() | ||
| localConfig := configuration.LocalConfig(cmd) | ||
|
|
||
| slug := args[0] | ||
|
|
||
| utils.RequireValue("token", localConfig.Token.Value) | ||
| utils.RequireValue("slug", slug) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: same here, let's check for a valid color before making the round trip to the server. |
||
| info, err := http.UpdateTag(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, slug, name, color) | ||
| if !err.IsNil() { | ||
| utils.HandleError(err.Unwrap(), err.Message) | ||
| } | ||
|
|
||
| if !utils.Silent { | ||
| printer.TagInfo(info, jsonFlag) | ||
| } | ||
| } | ||
|
|
||
| func deleteTag(cmd *cobra.Command, args []string) { | ||
| jsonFlag := utils.OutputJSON | ||
| yes := utils.GetBoolFlag(cmd, "yes") | ||
| localConfig := configuration.LocalConfig(cmd) | ||
|
|
||
| slug := args[0] | ||
|
|
||
| utils.RequireValue("token", localConfig.Token.Value) | ||
| utils.RequireValue("slug", slug) | ||
|
|
||
| if yes || utils.ConfirmationPrompt(fmt.Sprintf("Delete tag %s", slug), false) { | ||
| err := http.DeleteTag(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, slug) | ||
| if !err.IsNil() { | ||
| utils.HandleError(err.Unwrap(), err.Message) | ||
| } | ||
|
|
||
| if !utils.Silent { | ||
| info, err := http.GetTags(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value) | ||
| if !err.IsNil() { | ||
| utils.HandleError(err.Unwrap(), err.Message) | ||
| } | ||
|
|
||
| printer.TagsInfo(info, jsonFlag) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func tagSlugsValidArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
| persistentValidArgsFunction(cmd) | ||
|
|
||
| localConfig := configuration.LocalConfig(cmd) | ||
| slugs, err := controllers.GetTagSlugs(localConfig) | ||
| if err.IsNil() { | ||
| return slugs, cobra.ShellCompDirectiveNoFileComp | ||
| } | ||
| return nil, cobra.ShellCompDirectiveNoFileComp | ||
| } | ||
|
|
||
| func init() { | ||
| tagsCmd.AddCommand(tagsGetCmd) | ||
|
|
||
| tagsCreateCmd.Flags().String("color", "", fmt.Sprintf("tag color. One of: %s", validTagColorsList)) | ||
| tagsCreateCmd.Flags().String("slug", "", "tag slug (generated from the name when omitted)") | ||
| tagsCmd.AddCommand(tagsCreateCmd) | ||
|
|
||
| tagsUpdateCmd.Flags().String("name", "", "new name") | ||
| tagsUpdateCmd.Flags().String("color", "", fmt.Sprintf("new color. One of: %s", validTagColorsList)) | ||
| tagsCmd.AddCommand(tagsUpdateCmd) | ||
|
|
||
| tagsDeleteCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation") | ||
| tagsCmd.AddCommand(tagsDeleteCmd) | ||
|
|
||
| rootCmd.AddCommand(tagsCmd) | ||
| } | ||
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,37 @@ | ||
| /* | ||
| Copyright © 2026 Doppler <support@doppler.com> | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| package controllers | ||
|
|
||
| import ( | ||
| "github.com/DopplerHQ/cli/pkg/http" | ||
| "github.com/DopplerHQ/cli/pkg/models" | ||
| "github.com/DopplerHQ/cli/pkg/utils" | ||
| ) | ||
|
|
||
| func GetTagSlugs(config models.ScopedOptions) ([]string, Error) { | ||
| utils.RequireValue("token", config.Token.Value) | ||
|
|
||
| tags, err := http.GetTags(config.APIHost.Value, utils.GetBool(config.VerifyTLS.Value, true), config.Token.Value) | ||
| if !err.IsNil() { | ||
| return nil, Error{Err: err.Unwrap(), Message: err.Message} | ||
| } | ||
|
|
||
| var slugs []string | ||
| for _, tag := range tags { | ||
| slugs = append(slugs, tag.Slug) | ||
| } | ||
| return slugs, Error{} | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we should probably check to see if the color is actually a valid color here in the handler as opposed to sending it off to the server and having it error there.