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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ gog sheets banding set <spreadsheetId> 'Sheet1!A1:D100'
```bash
gog slides create-from-markdown "Weekly update" --content-file slides.md
gog slides insert-text <presentationId> <objectId> "New text"
gog forms publish <formId>
gog forms responses list <formId> --json
gog forms raw <formId> --pretty
```
Expand Down
1 change: 1 addition & 0 deletions docs/commands.generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ Generated from `gog schema --json`.
- [`gog forms (form) delete-question (delete-q,dq,rm-q) <formId> <index>`](commands/gog-forms-delete-question.md) - Delete a question by index
- [`gog forms (form) get (info,show) <formId>`](commands/gog-forms-get.md) - Get a form
- [`gog forms (form) move-question (move-q,mq) <formId> <oldIndex> <newIndex>`](commands/gog-forms-move-question.md) - Move a question to a new position
- [`gog forms (form) publish <formId> [flags]`](commands/gog-forms-publish.md) - Publish or unpublish a form
- [`gog forms (form) raw <formId> [flags]`](commands/gog-forms-raw.md) - Dump raw Google Forms API response as JSON (Forms.Get; lossless; for scripting and LLM consumption)
- [`gog forms (form) responses <command>`](commands/gog-forms-responses.md) - Form responses
- [`gog forms (form) responses get (info,show) <formId> <responseId>`](commands/gog-forms-responses-get.md) - Get a form response
Expand Down
3 changes: 2 additions & 1 deletion docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Every `gog` command has a generated docs page. The source of truth is the live CLI schema; run `make docs-commands` after changing command names, flags, help text, aliases, or arguments.

Generated pages: 470.
Generated pages: 471.

## Top-level Commands

Expand Down Expand Up @@ -311,6 +311,7 @@ Generated pages: 470.
- [gog forms delete-question](gog-forms-delete-question.md) - Delete a question by index
- [gog forms get](gog-forms-get.md) - Get a form
- [gog forms move-question](gog-forms-move-question.md) - Move a question to a new position
- [gog forms publish](gog-forms-publish.md) - Publish or unpublish a form
- [gog forms raw](gog-forms-raw.md) - Dump raw Google Forms API response as JSON (Forms.Get; lossless; for scripting and LLM consumption)
- [gog forms responses](gog-forms-responses.md) - Form responses
- [gog forms responses get](gog-forms-responses-get.md) - Get a form response
Expand Down
44 changes: 44 additions & 0 deletions docs/commands/gog-forms-publish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# `gog forms publish`

> Generated from `gog schema --json`. Do not edit this page by hand; run `make docs-commands`.

Publish or unpublish a form

## Usage

```bash
gog forms (form) publish <formId> [flags]
```

## Parent

- [gog forms](gog-forms.md)

## Flags

| Flag | Type | Default | Help |
| --- | --- | --- | --- |
| `--accepting-responses` | `bool` | true | Whether a published form accepts responses |
| `--access-token` | `string` | | Use provided access token directly (bypasses stored refresh tokens; token expires in ~1h) |
| `-a`<br>`--account`<br>`--acct` | `string` | | Account email for API commands (gmail/calendar/chat/classroom/drive/docs/slides/contacts/tasks/people/sheets/forms/appscript/ads) |
| `--client` | `string` | | OAuth client name (selects stored credentials + token bucket) |
| `--color` | `string` | auto | Color output: auto\|always\|never |
| `--disable-commands` | `string` | | Comma-separated list of disabled commands; dot paths allowed |
| `-n`<br>`--dry-run`<br>`--dryrun`<br>`--noop`<br>`--preview` | `bool` | | Do not make changes; print intended actions and exit successfully |
| `--enable-commands` | `string` | | Comma-separated list of enabled commands; dot paths allowed (restricts CLI) |
| `-y`<br>`--force`<br>`--assume-yes`<br>`--yes` | `bool` | | Skip confirmations for destructive commands |
| `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) |
| `-h`<br>`--help` | `kong.helpFlag` | | Show context-sensitive help. |
| `-j`<br>`--json`<br>`--machine` | `bool` | false | Output JSON to stdout (best for scripting) |
| `--no-input`<br>`--non-interactive`<br>`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) |
| `-p`<br>`--plain`<br>`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) |
| `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) |
| `--select`<br>`--pick`<br>`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. |
| `--unpublish` | `bool` | | Unpublish the form instead of publishing it |
| `-v`<br>`--verbose` | `bool` | | Enable verbose logging |
| `--version` | `kong.VersionFlag` | | Print version and exit |

## See Also

- [gog forms](gog-forms.md)
- [Command index](README.md)
1 change: 1 addition & 0 deletions docs/commands/gog-forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ gog forms (form) <command> [flags]
- [gog forms delete-question](gog-forms-delete-question.md) - Delete a question by index
- [gog forms get](gog-forms-get.md) - Get a form
- [gog forms move-question](gog-forms-move-question.md) - Move a question to a new position
- [gog forms publish](gog-forms-publish.md) - Publish or unpublish a form
- [gog forms raw](gog-forms-raw.md) - Dump raw Google Forms API response as JSON (Forms.Get; lossless; for scripting and LLM consumption)
- [gog forms responses](gog-forms-responses.md) - Form responses
- [gog forms update](gog-forms-update.md) - Update form title, description, or settings
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/forms.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type FormsCmd struct {
Get FormsGetCmd `cmd:"" name:"get" aliases:"info,show" help:"Get a form"`
Create FormsCreateCmd `cmd:"" name:"create" aliases:"new" help:"Create a form"`
Update FormsUpdateCmd `cmd:"" name:"update" aliases:"edit" help:"Update form title, description, or settings"`
Publish FormsPublishCmd `cmd:"" name:"publish" help:"Publish or unpublish a form"`
AddQuestion FormsAddQuestionCmd `cmd:"" name:"add-question" aliases:"add-q,aq" help:"Add a question to a form"`
DeleteQuestion FormsDeleteQuestionCmd `cmd:"" name:"delete-question" aliases:"delete-q,dq,rm-q" help:"Delete a question by index"`
MoveQuestion FormsMoveQuestionCmd `cmd:"" name:"move-question" aliases:"move-q,mq" help:"Move a question to a new position"`
Expand Down
112 changes: 112 additions & 0 deletions internal/cmd/forms_publish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package cmd

import (
"context"
"os"
"strings"

formsapi "google.golang.org/api/forms/v1"

"github.com/steipete/gogcli/internal/outfmt"
"github.com/steipete/gogcli/internal/ui"
)

// FormsPublishCmd publishes a form via forms.setPublishSettings.
type FormsPublishCmd struct {
FormID string `arg:"" name:"formId" help:"Form ID"`
Unpublish bool `name:"unpublish" help:"Unpublish the form instead of publishing it"`
AcceptingResponses bool `name:"accepting-responses" help:"Whether a published form accepts responses" default:"true"`
}

func (c *FormsPublishCmd) Run(ctx context.Context, flags *RootFlags) error {
published := !c.Unpublish
acceptingResponses := c.AcceptingResponses
if !published {
acceptingResponses = false
}
operation := "forms.publish"
if !published {
operation = "forms.unpublish"
}

return setFormPublishState(ctx, flags, formPublishStateRequest{
FormID: c.FormID,
Published: published,
AcceptingResponses: acceptingResponses,
Operation: operation,
})
}

type formPublishStateRequest struct {
FormID string
Published bool
AcceptingResponses bool
Operation string
}

func setFormPublishState(ctx context.Context, flags *RootFlags, publishReq formPublishStateRequest) error {
account, err := requireAccount(flags)
if err != nil {
return err
}
formID := strings.TrimSpace(normalizeGoogleID(publishReq.FormID))
if formID == "" {
return usage("empty formId")
}

if dryRunErr := dryRunExit(ctx, flags, publishReq.Operation, map[string]any{
"form_id": formID,
"published": publishReq.Published,
"accepting_responses": publishReq.AcceptingResponses,
}); dryRunErr != nil {
return dryRunErr
}

svc, err := newFormsService(ctx, account)
if err != nil {
return err
}

req := &formsapi.SetPublishSettingsRequest{
UpdateMask: "publish_state",
PublishSettings: &formsapi.PublishSettings{
PublishState: &formsapi.PublishState{
IsPublished: publishReq.Published,
IsAcceptingResponses: publishReq.AcceptingResponses,
ForceSendFields: []string{"IsPublished", "IsAcceptingResponses"},
},
},
}
resp, err := svc.Forms.SetPublishSettings(formID, req).Context(ctx).Do()
if err != nil {
return err
}

form, err := svc.Forms.Get(formID).Context(ctx).Do()
if err != nil {
return err
}

responderURI := strings.TrimSpace(form.ResponderUri)
if outfmt.IsJSON(ctx) {
return outfmt.WriteJSON(ctx, os.Stdout, map[string]any{
"published": publishReq.Published,
"accepting_responses": publishReq.AcceptingResponses,
"form_id": formID,
"responder_uri": responderURI,
"edit_url": formEditURL(formID),
"publish_settings": resp.PublishSettings,
"form": form,
})
}

u := ui.FromContext(ctx)
u.Out().Printf("published\t%t", publishReq.Published)
u.Out().Printf("accepting_responses\t%t", publishReq.AcceptingResponses)
u.Out().Printf("form_id\t%s", formID)
if responderURI != "" {
u.Out().Printf("responder_uri\t%s", responderURI)
}
u.Out().Printf("edit_url\t%s", formEditURL(formID))
return nil
}
Loading