diff --git a/shortcuts/sheets/data/flag-defs.json b/shortcuts/sheets/data/flag-defs.json index 94799aac..d003282d 100644 --- a/shortcuts/sheets/data/flag-defs.json +++ b/shortcuts/sheets/data/flag-defs.json @@ -4912,7 +4912,7 @@ "name": "transaction-id", "kind": "own", "type": "string", - "required": "optional", + "required": "required", "desc": "Async revert transaction id (from +history-revert)." }, { diff --git a/shortcuts/sheets/flag_defs_gen.go b/shortcuts/sheets/flag_defs_gen.go index aa1401f0..1228d0c4 100644 --- a/shortcuts/sheets/flag_defs_gen.go +++ b/shortcuts/sheets/flag_defs_gen.go @@ -669,7 +669,7 @@ var flagDefs = map[string]commandDef{ Flags: []flagDef{ {Name: "url", Kind: "public", Type: "string", Required: "xor", Desc: "Spreadsheet locator"}, {Name: "spreadsheet-token", Kind: "public", Type: "string", Required: "xor", Desc: "Spreadsheet locator"}, - {Name: "transaction-id", Kind: "own", Type: "string", Required: "optional", Desc: "Async revert transaction id (from +history-revert)."}, + {Name: "transaction-id", Kind: "own", Type: "string", Required: "required", Desc: "Async revert transaction id (from +history-revert)."}, {Name: "dry-run", Kind: "system", Type: "bool", Required: "optional"}, }, }, diff --git a/shortcuts/sheets/lark_sheet_history_revert.go b/shortcuts/sheets/lark_sheet_history_revert.go index 8dda70b7..249b3e8c 100644 --- a/shortcuts/sheets/lark_sheet_history_revert.go +++ b/shortcuts/sheets/lark_sheet_history_revert.go @@ -71,11 +71,15 @@ func historyRevertInput(token, versionID string) map[string]interface{} { // transactionIDFlag is the async-revert receipt selector used by // +history-revert-status: the transaction_id returned by +history-revert (NOT a // history version id — the facade-agg status tool keys on transaction_id). +// Required at the cli surface (cobra MarkFlagRequired) — same gating model as +// historyVersionIDFlag. Validate still trims + rejects empty/control-char +// values to catch the "--transaction-id ''" cobra-accepts-but-empty case. func transactionIDFlag() common.Flag { return common.Flag{ - Name: "transaction-id", - Type: "string", - Desc: "Async revert transaction id (from +history-revert). Required.", + Name: "transaction-id", + Type: "string", + Required: true, + Desc: "Async revert transaction id (from +history-revert).", } } diff --git a/shortcuts/sheets/lark_sheet_history_test.go b/shortcuts/sheets/lark_sheet_history_test.go index 5864aff7..2e83b2fd 100644 --- a/shortcuts/sheets/lark_sheet_history_test.go +++ b/shortcuts/sheets/lark_sheet_history_test.go @@ -4,11 +4,9 @@ package sheets import ( - "errors" "strings" "testing" - "github.com/larksuite/cli/errs" "github.com/larksuite/cli/shortcuts/common" ) @@ -132,14 +130,11 @@ func TestHistoryRevert_MissingRequiredFlag(t *testing.T) { t.Parallel() _, _, err := runShortcutCapturingErr(t, HistoryRevertStatus, []string{"--url", testURL}) if err == nil { - t.Fatalf("%s: expected validation error for missing --transaction-id", HistoryRevertStatus.Command) + t.Fatalf("%s: expected error for missing --transaction-id", HistoryRevertStatus.Command) } - var validationErr *errs.ValidationError - if !errors.As(err, &validationErr) { - t.Fatalf("%s: error = %T %v, want *errs.ValidationError", HistoryRevertStatus.Command, err, err) - } - if validationErr.Param != "--transaction-id" { - t.Fatalf("%s: param = %q, want --transaction-id", HistoryRevertStatus.Command, validationErr.Param) + msg := err.Error() + if !strings.Contains(msg, "required flag(s)") || !strings.Contains(msg, "transaction-id") { + t.Fatalf("%s: cobra error = %q, want substrings 'required flag(s)' and 'transaction-id'", HistoryRevertStatus.Command, msg) } }) }