MCPcopy Create free account
hub / github.com/openclaw/gogcli / Run

Method Run

internal/cmd/sheets.go:712–812  ·  view source on GitHub ↗
(ctx context.Context, flags *RootFlags)

Source from the content-addressed store, hash-verified

710}
711
712func (c *SheetsCreateCmd) Run(ctx context.Context, flags *RootFlags) error {
713 u := ui.FromContext(ctx)
714 title := strings.TrimSpace(c.Title)
715 if title == "" {
716 return usage("empty title")
717 }
718
719 names := splitCSV(c.Sheets)
720 parent := normalizeGoogleID(strings.TrimSpace(c.Parent))
721 if err := dryRunExit(ctx, flags, "sheets.create", map[string]any{
722 "title": title,
723 "sheets": names,
724 "parent": parent,
725 }); err != nil {
726 return err
727 }
728
729 account, err := requireAccount(flags)
730 if err != nil {
731 return err
732 }
733
734 svc, err := sheetsService(ctx, account)
735 if err != nil {
736 return err
737 }
738
739 spreadsheet := &sheets.Spreadsheet{
740 Properties: &sheets.SpreadsheetProperties{
741 Title: title,
742 },
743 }
744
745 if len(names) > 0 {
746 spreadsheet.Sheets = make([]*sheets.Sheet, len(names))
747 for i, name := range names {
748 spreadsheet.Sheets[i] = &sheets.Sheet{
749 Properties: &sheets.SheetProperties{
750 Title: strings.TrimSpace(name),
751 },
752 }
753 }
754 }
755
756 resp, err := svc.Spreadsheets.Create(spreadsheet).Do()
757 if err != nil {
758 return err
759 }
760
761 movedToParent := false
762 moveError := ""
763 if parent != "" {
764 parentDriveSvc, driveErr := driveService(ctx, account)
765 if driveErr == nil {
766 var meta *drive.File
767 meta, driveErr = parentDriveSvc.Files.Get(resp.SpreadsheetId).
768 SupportsAllDrives(true).
769 Fields("id, parents").

Callers

nothing calls this directly

Calls 15

FromContextFunction · 0.92
IsJSONFunction · 0.92
WriteJSONFunction · 0.92
usageFunction · 0.85
splitCSVFunction · 0.85
normalizeGoogleIDFunction · 0.85
dryRunExitFunction · 0.85
requireAccountFunction · 0.85
sheetsServiceFunction · 0.85
driveServiceFunction · 0.85
stdoutWriterFunction · 0.85
CreateMethod · 0.80

Tested by

no test coverage detected