fix(cli): rune-safe truncateID, consistent client construction, add --output to status cmd
- Make truncateID use rune counting instead of byte length for unicode safety - Refactor workspaceGet and workspaceMembers to use newAPIClient helper for consistent server-URL validation - Add --output flag to issueStatusCmd for JSON output support Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4a62b98c9a
commit
673ba09baf
2 changed files with 19 additions and 13 deletions
|
|
@ -133,6 +133,9 @@ func init() {
|
|||
issueUpdateCmd.Flags().String("due-date", "", "New due date (RFC3339 format)")
|
||||
issueUpdateCmd.Flags().String("output", "json", "Output format: table or json")
|
||||
|
||||
// issue status
|
||||
issueStatusCmd.Flags().String("output", "table", "Output format: table or json")
|
||||
|
||||
// issue assign
|
||||
issueAssignCmd.Flags().String("to", "", "Assignee name (member or agent)")
|
||||
issueAssignCmd.Flags().Bool("unassign", false, "Remove current assignee")
|
||||
|
|
@ -459,11 +462,17 @@ func runIssueStatus(cmd *cobra.Command, args []string) error {
|
|||
defer cancel()
|
||||
|
||||
body := map[string]any{"status": status}
|
||||
if err := client.PutJSON(ctx, "/api/issues/"+id, body, nil); err != nil {
|
||||
var result map[string]any
|
||||
if err := client.PutJSON(ctx, "/api/issues/"+id, body, &result); err != nil {
|
||||
return fmt.Errorf("update status: %w", err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Issue %s status changed to %s.\n", truncateID(id), status)
|
||||
|
||||
output, _ := cmd.Flags().GetString("output")
|
||||
if output == "json" {
|
||||
return cli.PrintJSON(os.Stdout, result)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -643,8 +652,9 @@ func formatAssignee(issue map[string]any) string {
|
|||
}
|
||||
|
||||
func truncateID(id string) string {
|
||||
if len(id) > 8 {
|
||||
return id[:8]
|
||||
if utf8.RuneCountInString(id) > 8 {
|
||||
runes := []rune(id)
|
||||
return string(runes[:8])
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,13 +119,11 @@ func runWorkspaceGet(cmd *cobra.Command, args []string) error {
|
|||
return fmt.Errorf("workspace ID is required: pass as argument or set MULTICA_WORKSPACE_ID")
|
||||
}
|
||||
|
||||
serverURL := resolveServerURL(cmd)
|
||||
token := resolveToken()
|
||||
if token == "" {
|
||||
return fmt.Errorf("not authenticated: run 'multica auth login' first")
|
||||
client, err := newAPIClient(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client := cli.NewAPIClient(serverURL, "", token)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
|
@ -167,13 +165,11 @@ func runWorkspaceMembers(cmd *cobra.Command, args []string) error {
|
|||
return fmt.Errorf("workspace ID is required: pass as argument or set MULTICA_WORKSPACE_ID")
|
||||
}
|
||||
|
||||
serverURL := resolveServerURL(cmd)
|
||||
token := resolveToken()
|
||||
if token == "" {
|
||||
return fmt.Errorf("not authenticated: run 'multica auth login' first")
|
||||
client, err := newAPIClient(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client := cli.NewAPIClient(serverURL, "", token)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue