fix(cmdutils): show error text as written
Description
glab capitalizes the first word of every error message. This breaks text where case matters: flags (--Title, '--Stdin'), acronyms (JSON becomes Json), config keys and paths.
This happens in a terminal, and also when stderr is not a terminal (CI logs, scripts, stderr sent to a file).
Now glab shows the error text exactly as written, in both cases.
At first I only skipped the capital letter for errors that start with -. That still broke quoted flags like '--stdin' and acronyms, so now no error text is changed.
One decision for you:
- Errors that start with a normal word no longer get a capital first letter. For example,
could not prompt: ...instead ofCould not prompt: .... Scripts that match the old capitalized text will see the lowercase word too. Is this ok? If not, I can keep the capital letter only for errors that start with a lowercase letter.
Related Issues
Closes #8619
How has this been tested?
I built glab from main (glab-main) and from this branch (glab-8619), and ran glab auth login with a temp HOME and GLAB_CONFIG_DIR:
$ GLAB_NO_PROMPT=true CLICOLOR_FORCE=1 script -q -c "./glab-main auth login" /dev/null
ERROR
'--Stdin', '--token', '--job-token', '--web', or '--device' required when not running interactively.
$ GLAB_NO_PROMPT=true CLICOLOR_FORCE=1 script -q -c "./glab-8619 auth login" /dev/null
ERROR
'--stdin', '--token', '--job-token', '--web', or '--device' required when not running interactively.The same happens with stderr sent to a file:
$ ./glab-main snippet create note.txt 2>err-main.txt
$ cat err-main.txt
ERROR
--Title required for snippets.
$ ./glab-8619 snippet create note.txt 2>err-8619.txt
$ cat err-8619.txt
ERROR
--title required for snippets.This is the visible effect from decision 1:
$ CLICOLOR_FORCE=1 script -q -c "./glab-main auth login </dev/null" /dev/null
ERROR
Could not prompt: huh: bubbletea: could not create cancelable reader: add reader to epoll interest list.
$ CLICOLOR_FORCE=1 script -q -c "./glab-8619 auth login </dev/null" /dev/null
ERROR
could not prompt: huh: bubbletea: could not create cancelable reader: add reader to epoll interest list.I added tests for a long flag, a short flag, a quoted flag list, a flag in backticks, an acronym and a normal sentence. The new tests fail without the fix.
$ GOFLAGS=-p=2 go test -count=1 ./internal/cmdutils/
ok gitlab.com/gitlab-org/cli/internal/cmdutils 2.226sThe rest runs in the pipeline.
Implemented with AI assistance; I reviewed and tested the changes.