Rename the --tab-id flag to --tab on all docs editing commands (write, update, insert, delete, find-replace) to match the convention already used by cat, structure, sed, and the new export command. The old --tab-id flag is preserved as a hidden alias that emits a deprecation warning to stderr. Also switches the internal helpers (docsTargetEndIndex, loadDocsTargetDocument) from findTabByID to findTab so that --tab resolves by title as well as ID. Removes the now-unused findTabByID. (cherry picked from commit 50e69365539483b8b17f697d1391656b324a67af)
76 lines
1.4 KiB
Go
76 lines
1.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func captureHelpOutput(t *testing.T, args ...string) string {
|
|
t.Helper()
|
|
return captureStdout(t, func() {
|
|
_ = captureStderr(t, func() {
|
|
if err := Execute(args); err != nil {
|
|
t.Fatalf("Execute(%v): %v", args, err)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
func requireHelpContains(t *testing.T, out string, parts ...string) {
|
|
t.Helper()
|
|
for _, part := range parts {
|
|
if !strings.Contains(out, part) {
|
|
t.Fatalf("expected help to contain %q, got: %q", part, out)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestHelpSnapshot_Auth(t *testing.T) {
|
|
out := captureHelpOutput(t, "auth", "--help")
|
|
requireHelpContains(t, out,
|
|
"\n add",
|
|
"\n credentials",
|
|
"\n tokens",
|
|
"\n alias",
|
|
)
|
|
}
|
|
|
|
func TestHelpSnapshot_DocsUpdate(t *testing.T) {
|
|
out := captureHelpOutput(t, "docs", "update", "--help")
|
|
requireHelpContains(t, out,
|
|
"--tab",
|
|
"--text",
|
|
"--file",
|
|
"--index",
|
|
)
|
|
}
|
|
|
|
func TestHelpSnapshot_Sheets(t *testing.T) {
|
|
out := captureHelpOutput(t, "sheets", "--help")
|
|
requireHelpContains(t, out,
|
|
"\n add-tab",
|
|
"\n rename-tab",
|
|
"\n delete-tab",
|
|
"\n named-ranges",
|
|
"\n update-note",
|
|
)
|
|
}
|
|
|
|
func TestHelpSnapshot_Forms(t *testing.T) {
|
|
out := captureHelpOutput(t, "forms", "--help")
|
|
requireHelpContains(t, out,
|
|
"\n create",
|
|
"\n update",
|
|
"\n add-question",
|
|
"\n watch",
|
|
)
|
|
}
|
|
|
|
func TestHelpSnapshot_Admin(t *testing.T) {
|
|
out := captureHelpOutput(t, "admin", "--help")
|
|
requireHelpContains(t, out,
|
|
"\n users",
|
|
"\n groups",
|
|
)
|
|
}
|