(ctx context.Context, flags *RootFlags)
| 190 | } |
| 191 | |
| 192 | func (c *AppScriptCreateCmd) Run(ctx context.Context, flags *RootFlags) error { |
| 193 | title := strings.TrimSpace(c.Title) |
| 194 | if title == "" { |
| 195 | return usage("empty --title") |
| 196 | } |
| 197 | parentID := strings.TrimSpace(normalizeGoogleID(c.ParentID)) |
| 198 | |
| 199 | if dryRunErr := dryRunExit(ctx, flags, "appscript.create", map[string]any{ |
| 200 | "title": title, |
| 201 | "parent_id": parentID, |
| 202 | }); dryRunErr != nil { |
| 203 | return dryRunErr |
| 204 | } |
| 205 | |
| 206 | account, err := requireAccount(flags) |
| 207 | if err != nil { |
| 208 | return err |
| 209 | } |
| 210 | |
| 211 | svc, err := appScriptService(ctx, account) |
| 212 | if err != nil { |
| 213 | return err |
| 214 | } |
| 215 | project, err := svc.Projects.Create(&scriptapi.CreateProjectRequest{ |
| 216 | Title: title, |
| 217 | ParentId: parentID, |
| 218 | }).Context(ctx).Do() |
| 219 | if err != nil { |
| 220 | return err |
| 221 | } |
| 222 | |
| 223 | if outfmt.IsJSON(ctx) { |
| 224 | return outfmt.WriteJSON(ctx, stdoutWriter(ctx), map[string]any{ |
| 225 | "created": true, |
| 226 | "project": project, |
| 227 | "editor_url": appScriptEditURL(project.ScriptId), |
| 228 | }) |
| 229 | } |
| 230 | |
| 231 | u := ui.FromContext(ctx) |
| 232 | u.Out().Linef("created\ttrue") |
| 233 | u.Out().Linef("script_id\t%s", project.ScriptId) |
| 234 | if project.Title != "" { |
| 235 | u.Out().Linef("title\t%s", project.Title) |
| 236 | } |
| 237 | if project.ParentId != "" { |
| 238 | u.Out().Linef("parent_id\t%s", project.ParentId) |
| 239 | } |
| 240 | u.Out().Linef("editor_url\t%s", appScriptEditURL(project.ScriptId)) |
| 241 | return nil |
| 242 | } |
| 243 | |
| 244 | func parseJSONArray(raw string) ([]interface{}, error) { |
| 245 | val := strings.TrimSpace(raw) |
nothing calls this directly
no test coverage detected