-
-
Notifications
You must be signed in to change notification settings - Fork 5
Add support for issue.category #104
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,85 @@ | ||||||
| package config | ||||||
|
|
||||||
| import ( | ||||||
| "strconv" | ||||||
|
|
||||||
| "github.com/MrJeffLarry/redmine-cli/internal/config" | ||||||
| "github.com/MrJeffLarry/redmine-cli/internal/print" | ||||||
| "github.com/spf13/cobra" | ||||||
| ) | ||||||
|
|
||||||
| func getCategoryID(r *config.Red_t, cmd *cobra.Command) (int, error) { | ||||||
| var id int | ||||||
| var err error | ||||||
|
|
||||||
| if id, err = strconv.Atoi(cmd.Flags().Arg(0)); err != nil { | ||||||
| print.Error("ID is not an valid number, please use `category set 1` for category id 1") | ||||||
| return 0, err | ||||||
| } | ||||||
| return id, nil | ||||||
| } | ||||||
|
|
||||||
| func setLocalCategory(r *config.Red_t) *cobra.Command { | ||||||
| cmd := &cobra.Command{ | ||||||
| Use: "set [id]", | ||||||
| Short: "set local category", | ||||||
| Long: "set a local category under .red/config.json", | ||||||
| Run: func(cmd *cobra.Command, args []string) { | ||||||
| var id int | ||||||
| var err error | ||||||
| if id, err = getCategoryID(r, cmd); err != nil { | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| if err := r.SaveLocalCategory(id); err != nil { | ||||||
| print.Error("%s [%s]", "Could not save category, please verify permissions", err) | ||||||
| return | ||||||
| } | ||||||
| print.OK("Category locally set to ID #%d", id) | ||||||
| }, | ||||||
| } | ||||||
| return cmd | ||||||
| } | ||||||
|
|
||||||
| func setGlobalCategory(r *config.Red_t) *cobra.Command { | ||||||
| cmd := &cobra.Command{ | ||||||
| Use: "set [id]", | ||||||
| Short: "set global category", | ||||||
| Long: "set a global category under ~/.red/config.json", | ||||||
| Run: func(cmd *cobra.Command, args []string) { | ||||||
| var id int | ||||||
| var err error | ||||||
| if id, err = getCategoryID(r, cmd); err != nil { | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| r.SetCategoryID(id) | ||||||
| if err := r.Save(); err != nil { | ||||||
| print.Error("%s [%s]", "Could not save category, please verify permissions", err) | ||||||
| return | ||||||
| } | ||||||
| print.OK("Category globally set to ID #%d", id) | ||||||
| }, | ||||||
| } | ||||||
| return cmd | ||||||
| } | ||||||
|
|
||||||
| func localCategory(r *config.Red_t) *cobra.Command { | ||||||
| cmd := &cobra.Command{ | ||||||
| Use: "category", | ||||||
| Short: "set or get local category", | ||||||
| Long: "set or get a local category under ~/.red/config.json", | ||||||
|
||||||
| Long: "set or get a local category under ~/.red/config.json", | |
| Long: "set or get a local category under .red/config.json", |
Copilot
AI
Dec 12, 2025
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.
The localCategory and globalCategory functions are defined but never registered with the config command structure. These functions need to be added to the configLocal and configGlobal functions in config.go (similar to how localProject and globalProject are registered) for the category commands to be accessible to users.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,8 @@ const ( | |||||||||
| RED_CONFIG_REDMINE_API_KEY = "RED_CONFIG_REDMINE_API_KEY" | ||||||||||
| RED_CONFIG_REDMINE_PROJECT = "RED_CONFIG_REDMINE_PROJECT" | ||||||||||
| RED_CONFIG_REDMINE_PROJECT_ID = "RED_CONFIG_REDMINE_PROJECT_ID" | ||||||||||
| RED_CONFIG_REDMINE_CATEGORY = "RED_CONFIG_REDMINE_CATEGORY" | ||||||||||
| RED_CONFIG_REDMINE_CATEGORY_ID = "RED_CONFIG_REDMINE_CATEGORY_ID" | ||||||||||
| RED_CONFIG_REDMINE_USER_ID = "RED_CONFIG_REDMINE_USER_ID" | ||||||||||
| RED_CONFIG_EDITOR = "RED_CONFIG_EDITOR" | ||||||||||
| RED_CONFIG_PAGER = "RED_CONFIG_PAGER" | ||||||||||
|
|
@@ -29,6 +31,8 @@ const ( | |||||||||
| CONFIG_REDMINE_API_KEY = "api-key" | ||||||||||
| CONFIG_REDMINE_PROJECT = "project" | ||||||||||
| CONFIG_REDMINE_PROJECT_ID = "project-id" | ||||||||||
| CONFIG_REDMINE_CATEGORY = "category" | ||||||||||
| CONFIG_REDMINE_CATEGORY_ID = "category-id" | ||||||||||
| CONFIG_REDMINE_USER_ID = "user-id" | ||||||||||
| CONFIG_EDITOR = "editor" | ||||||||||
| CONFIG_PAGER = "pager" | ||||||||||
|
|
@@ -52,6 +56,8 @@ type Config_t struct { | |||||||||
| ApiKey string `mapstructure:"api-key"` | ||||||||||
| Project string `json:"project"` | ||||||||||
| ProjectID int `mapstructure:"project-id"` | ||||||||||
| Category string `json:"category"` | ||||||||||
| CategoryID int `mapstructure:"category-id"` | ||||||||||
| UserID int `mapstructure:"user-id"` | ||||||||||
| Editor string `json:"editor"` | ||||||||||
| Pager string `json:"pager"` | ||||||||||
|
|
@@ -103,6 +109,14 @@ func (r *Red_t) SetProjectID(id int) { | |||||||||
| r.Config.ProjectID = id | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func (r *Red_t) SetCategory(id string) { | ||||||||||
| r.Config.Category = id | ||||||||||
|
Comment on lines
+112
to
+113
|
||||||||||
| func (r *Red_t) SetCategory(id string) { | |
| r.Config.Category = id | |
| func (r *Red_t) SetCategory(category string) { | |
| r.Config.Category = category |
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.
Error message contains grammatical error 'an valid' which should be 'a valid'. The article 'an' is incorrectly used before a consonant sound.