Skip to content

Commit 7527b26

Browse files
alexknowshtmlclaude
andcommitted
feat(calendar): add create-calendar command
Create new secondary Google Calendars via the API. Usage: gog calendar create-calendar "My Calendar" --timezone America/New_York Supports --description, --timezone, --location flags. Outputs calendar ID and summary in both text and JSON modes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d25dbfd commit 7527b26

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

internal/cmd/calendar.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func newCalendarCmd(flags *rootFlags) *cobra.Command {
2121
Short: "Google Calendar",
2222
}
2323
cmd.AddCommand(newCalendarCalendarsCmd(flags))
24+
cmd.AddCommand(newCalendarCreateCalendarCmd(flags))
2425
cmd.AddCommand(newCalendarAclCmd(flags))
2526
cmd.AddCommand(newCalendarEventsCmd(flags))
2627
cmd.AddCommand(newCalendarEventCmd(flags))
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"strings"
7+
8+
"github.com/spf13/cobra"
9+
"github.com/steipete/gogcli/internal/outfmt"
10+
"github.com/steipete/gogcli/internal/ui"
11+
"google.golang.org/api/calendar/v3"
12+
)
13+
14+
func newCalendarCreateCalendarCmd(flags *rootFlags) *cobra.Command {
15+
var description string
16+
var timeZone string
17+
var location string
18+
19+
cmd := &cobra.Command{
20+
Use: "create-calendar <name>",
21+
Short: "Create a new secondary calendar",
22+
Args: cobra.ExactArgs(1),
23+
RunE: func(cmd *cobra.Command, args []string) error {
24+
u := ui.FromContext(cmd.Context())
25+
account, err := requireAccount(flags)
26+
if err != nil {
27+
return err
28+
}
29+
30+
name := strings.TrimSpace(args[0])
31+
if name == "" {
32+
return usage("required: calendar name")
33+
}
34+
35+
svc, err := newCalendarService(cmd.Context(), account)
36+
if err != nil {
37+
return err
38+
}
39+
40+
cal := &calendar.Calendar{
41+
Summary: name,
42+
Description: strings.TrimSpace(description),
43+
TimeZone: strings.TrimSpace(timeZone),
44+
Location: strings.TrimSpace(location),
45+
}
46+
47+
created, err := svc.Calendars.Insert(cal).Context(cmd.Context()).Do()
48+
if err != nil {
49+
return fmt.Errorf("create calendar: %w", err)
50+
}
51+
52+
if outfmt.IsJSON(cmd.Context()) {
53+
return outfmt.WriteJSON(os.Stdout, map[string]any{"calendar": created})
54+
}
55+
56+
u.Out().Printf("id\t%s", created.Id)
57+
u.Out().Printf("summary\t%s", created.Summary)
58+
if created.TimeZone != "" {
59+
u.Out().Printf("timezone\t%s", created.TimeZone)
60+
}
61+
if created.Description != "" {
62+
u.Out().Printf("description\t%s", created.Description)
63+
}
64+
return nil
65+
},
66+
}
67+
68+
cmd.Flags().StringVar(&description, "description", "", "Calendar description")
69+
cmd.Flags().StringVar(&timeZone, "timezone", "", "IANA timezone (e.g., America/New_York)")
70+
cmd.Flags().StringVar(&location, "location", "", "Calendar location")
71+
return cmd
72+
}

0 commit comments

Comments
 (0)