Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &cobra.Command{ Use: "get", Short: "Get data from a spreadsheet", PreRunE: func(cmd *cobra.Command, args []string) error { if cmd.Flag("spreadsheet-id").Value.String() == "" { return fmt.Errorf("spreadsheet ID is required") } if len(args) == 0 { return fmt.Errorf("range is required") } return nil }, RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() client := ctx.Value(shared.ClientContextKey).(*http.Client) srv, err := sheets.NewService(ctx, option.WithHTTPClient(client)) if err != nil { return fmt.Errorf("error retrieving Sheets client: %w", err) } spreadsheetId := cmd.Flag("spreadsheet-id").Value.String() encoder := json.NewEncoder(os.Stdout) for _, arg := range args { resp, err := srv.Spreadsheets.Values.Get(spreadsheetId, arg).Do() if err != nil { return fmt.Errorf("error retrieving data from sheet: %w", err) } if err := encoder.Encode(resp.Values); err != nil { return fmt.Errorf("error encoding JSON: %w", err) } } return nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.