mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(api): filter raw responses with --jq and end output with a newline
tea api /version --jq .version failed with "--jq requires --json", and --json is rejected for raw responses. api is annotated tea.rawjson now: --jq filters each successful JSON response, page by page with --paginate, and prints strings without quotes. A non-JSON response is an error with --jq; an error response prints its body unfiltered. JSON responses end with a newline, so an error no longer starts on the line of the body; on a terminal JSON is indented and colored in the key order of the response, and other text is sanitized as before. Piped non-JSON bodies stay byte-exact. api gains -i for --include and --silent, a Long help modeled on gh api (placeholders, -f/-F typing, pagination, --jq) and examples, and its help lists --jq. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
5 files changed
+209
-40
No files matched your search
@@ -154,8 +154,8 @@ func availableCommands(cmd *cobra.Command) []commandList {
|
||||
}
|
||||
|
||||
// helpFlags renders the flags of cmd and the global flags that apply to it: --repo, --remote and --cwd
|
||||
// unless it never selects a repository, --json and --jq when it outputs JSON, and --yes when it asks
|
||||
// for confirmation. Persistent flags of parent commands, such as --org, count as its own.
|
||||
// unless it never selects a repository, --json and --jq when it outputs JSON (--jq alone when it
|
||||
// filters raw JSON), and --yes when it asks for confirmation. Persistent flags of parent commands, such as --org, count as its own.
|
||||
func helpFlags(cmd *cobra.Command) (local, inherited string) {
|
||||
globals := cmd.Root().PersistentFlags()
|
||||
var own []*pflag.Flag
|
||||
@@ -169,7 +169,7 @@ func helpFlags(cmd *cobra.Command) (local, inherited string) {
|
||||
slices.SortFunc(own, func(x, y *pflag.Flag) int { return strings.Compare(x.Name, y.Name) })
|
||||
path := cmd.CommandPath()
|
||||
repo := !slices.ContainsFunc(noRepoCommands, func(prefix string) bool { return path == prefix || strings.HasPrefix(path, prefix+" ") })
|
||||
shown := map[string]bool{"repo": repo, "remote": repo, "cwd": repo, "json": outputsJSON(cmd), "jq": outputsJSON(cmd), "yes": cmd.Annotations["tea.confirm"] != ""}
|
||||
shown := map[string]bool{"repo": repo, "remote": repo, "cwd": repo, "json": outputsJSON(cmd), "jq": outputsJSON(cmd) || cmd.Annotations["tea.rawjson"] != "", "yes": cmd.Annotations["tea.confirm"] != ""}
|
||||
var shared []*pflag.Flag
|
||||
for _, name := range []string{"repo", "remote", "cwd", "json", "jq", "yes"} {
|
||||
if shown[name] {
|
||||
|
||||
Reference in new issue
Block a user