Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shortcuts/sheets/lark_sheets_cell_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ var SheetWrite = common.Shortcut{
{Name: "spreadsheet-token", Desc: "spreadsheet token"},
{Name: "range", Desc: "write range (<sheetId>!A1:D10, A1:D10 with --sheet-id, or a single cell like C2)"},
{Name: "sheet-id", Desc: "sheet ID"},
{Name: "values", Desc: "2D array JSON", Required: true},
{Name: "values", Desc: "2D array JSON (supports @file and - for stdin)", Required: true, Input: []string{common.File, common.Stdin}},
},
Validate: func(ctx context.Context, runtime *common.RuntimeContext) error {
if _, err := validateSheetManageToken(runtime); err != nil {
Expand Down Expand Up @@ -182,7 +182,7 @@ var SheetAppend = common.Shortcut{
{Name: "spreadsheet-token", Desc: "spreadsheet token"},
{Name: "range", Desc: "append range (<sheetId>!A1:D10, A1:D10 with --sheet-id, or a single cell like C2)"},
{Name: "sheet-id", Desc: "sheet ID"},
{Name: "values", Desc: "2D array JSON", Required: true},
{Name: "values", Desc: "2D array JSON (supports @file and - for stdin)", Required: true, Input: []string{common.File, common.Stdin}},
},
Validate: func(ctx context.Context, runtime *common.RuntimeContext) error {
if _, err := validateSheetManageToken(runtime); err != nil {
Expand Down
57 changes: 57 additions & 0 deletions shortcuts/sheets/lark_sheets_sheet_ranges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ package sheets
import (
"context"
"encoding/json"
"os"
"strings"
"testing"

"github.com/larksuite/cli/internal/cmdutil"
"github.com/larksuite/cli/shortcuts/common"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -126,6 +128,61 @@ func TestSheetAppendDryRunNormalizesEscapedSeparator(t *testing.T) {
}
}

func TestSheetWriteDryRunAcceptsValuesFileInput(t *testing.T) {
dir := t.TempDir()
cmdutil.TestChdir(t, dir)
if err := os.WriteFile("values.json", []byte(`[
["2025-01", "产品A"],
["2025-02", "产品B"]
]`), 0644); err != nil {
t.Fatal(err)
}

f, stdout, _, _ := cmdutil.TestFactory(t, sheetsTestConfig())
err := mountAndRunSheets(t, SheetWrite, []string{
"+write",
"--spreadsheet-token", "shtTOKEN",
"--range", "sheet1!A1",
"--values", "@values.json",
"--dry-run",
"--as", "user",
}, f, stdout)
if err != nil {
t.Fatalf("dry-run should accept --values @file, got: %v", err)
}
got := stdout.String()
if !strings.Contains(got, `"range": "sheet1!A1:A1"`) {
t.Fatalf("dry-run should include normalized write range: %s", got)
}
if !strings.Contains(got, `"产品B"`) {
t.Fatalf("dry-run should include values loaded from file: %s", got)
}
}

func TestSheetAppendDryRunAcceptsValuesStdinInput(t *testing.T) {
f, stdout, _, _ := cmdutil.TestFactory(t, sheetsTestConfig())
f.IOStreams.In = strings.NewReader(`[["2025-01","产品A"]]`)

err := mountAndRunSheets(t, SheetAppend, []string{
"+append",
"--spreadsheet-token", "shtTOKEN",
"--range", "sheet1!A1",
"--values", "-",
"--dry-run",
"--as", "user",
}, f, stdout)
if err != nil {
t.Fatalf("dry-run should accept --values - stdin, got: %v", err)
}
got := stdout.String()
if !strings.Contains(got, `"range": "sheet1!A1:A1"`) {
t.Fatalf("dry-run should preserve append point range: %s", got)
}
if !strings.Contains(got, `"产品A"`) {
t.Fatalf("dry-run should include values loaded from stdin: %s", got)
}
}

func TestSheetFindDryRunNormalizesEscapedSeparator(t *testing.T) {
t.Parallel()

Expand Down
Loading