Merge pull request 'Page an answer larger than one message of the bus, and keep overviews brief (hq issue 314)' (#138) from fix/314-a-large-answer-is-paged-not-lost into main
This commit was merged in pull request #138.
This commit is contained in:
@@ -673,6 +673,9 @@ func (a *verbArguments) commandLine() ([]string, error) {
|
||||
if which > 1 {
|
||||
return nil, errors.New("doctor answers one of run, probes or signals at a time")
|
||||
}
|
||||
if p := str("probe"); p != "" {
|
||||
argv = append(argv, "--probe", p)
|
||||
}
|
||||
return append(argv, "--json"), nil
|
||||
case "rotate":
|
||||
if p := str("provision"); p != "" {
|
||||
@@ -805,6 +808,11 @@ var jsonVerbs = map[string]bool{"status": true, "seats": true, "plan": true, "co
|
||||
// The delivery's owner's verbs answer JSON where they read (plan, order, check, walks) — novox/hq ADR 0239.
|
||||
"delivery": true}
|
||||
|
||||
// overviewVerbs are the JSON verbs whose answer is said once, as data, and not again as the text the
|
||||
// command printed: the overviews, which grow with the mesh (novox/hq issue 314). Every reader of theirs
|
||||
// reads `answer` first.
|
||||
var overviewVerbs = map[string]bool{"status": true, "conditions": true, "doctor": true}
|
||||
|
||||
// repairingCommand names a command line that repairs by hand, and so says why: a push, a plan stopped
|
||||
// or closed, a consumer re-made (novox/hq to-be 45 §7). Empty for any other.
|
||||
func repairingCommand(argv []string) string {
|
||||
@@ -870,6 +878,11 @@ func runVerb(ctx context.Context, argv []string) (verbAnswer, error) {
|
||||
var parsed any
|
||||
if json.Unmarshal(bytes.TrimSpace(stdout.Bytes()), &parsed) == nil {
|
||||
answer.Answer = parsed
|
||||
if overviewVerbs[argv[0]] {
|
||||
// Once, as data: the same document again as text doubled an answer that already
|
||||
// outgrew one message of the bus (novox/hq issue 314).
|
||||
answer.Output = stderr.String() + "its answer, as data, is `answer`\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
var exit *exec.ExitError
|
||||
@@ -923,10 +936,10 @@ func seatToolHandlers() (map[string]link.ToolHandler, []string, error) {
|
||||
return nil, err
|
||||
}
|
||||
sub := ""
|
||||
if len(argv) > 2 {
|
||||
if len(argv) > 2 && !strings.HasPrefix(argv[1], "-") {
|
||||
sub = argv[1]
|
||||
}
|
||||
return doctorAnswer(ctx, sub)
|
||||
return doctorAnswer(ctx, sub, a.given["probe"])
|
||||
}
|
||||
return seatTools(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user