Skip to content

feat(create): add --list flag to print available templates#1247

Draft
DaveHanns wants to merge 1 commit into
masterfrom
create-list-templates
Draft

feat(create): add --list flag to print available templates#1247
DaveHanns wants to merge 1 commit into
masterfrom
create-list-templates

Conversation

@DaveHanns

Copy link
Copy Markdown
Contributor

Summary

Adds a --list flag to apify create so template ids can be discovered non-interactively (agent contexts, CI, non-TTY shells) without visiting the actor-templates GitHub repo or hitting the interactive picker. Combined with --json, the output is machine-parseable.

Addresses finding F34 — no non-interactive discovery path exists today for apify create --template <id>, which is the only way to invoke the command from an agent.

What changes

  • src/commands/create.ts
    • New list: Flags.boolean(...) flag (no char; --list only, to avoid clashing with common short-flag conventions).
    • static override enableJsonFlag = true so the framework's built-in --json support is available on this command.
    • Two new examples in static examples (apify create --list and apify create --list --json).
    • New early-return branch at the top of run(), after the manifest fetch is kicked off but before any actor-name validation or filesystem mkdir. Reuses the same fetchManifest() mechanism the interactive picker already uses — no new dependency, no new HTTP client, no new fetch URL. Fields exposed: id (mapped from Template.name, matching what --template accepts), label, category (language), description.
    • Text form uses tab-separated output (<id>\t<language>\t<description>) so it pipes cleanly through awk / cut.

No existing behavior changes — apify create without --list is identical to before.

Test plan

  • pnpm exec tsc --noEmit -p . passes (verified locally).
  • pnpm exec oxlint --type-aware src/commands/create.ts passes (verified locally).
  • apify create --list in a non-TTY shell prints tab-separated <id>\t<language>\t<description> lines and exits 0 without creating a directory.
  • apify create --list --json prints a {"templates": [...]} JSON object with id, label, category, description fields and exits 0.
  • apify create my-actor --template <id-from-list> --skip-dependency-install still works (no regression on the create path).
  • apify create with no args still triggers the interactive picker (no regression on interactive path).

Notes for reviewers

  • The choice to key the JSON on id: t.name (rather than Template.id) matches the string that --template accepts today; getTemplateDefinition looks up by t.name === maybeTemplateName. Exposing anything else would be confusing.
  • No test file added yet — the interactive picker is not covered by unit tests either, and adding one would require mocking the manifest fetch. Happy to add a test in a follow-up if reviewers prefer.

Today, discovering template ids requires either visiting the
actor-templates GitHub repo or running `apify create` with its
interactive picker, which fails in non-TTY / agent contexts. There is
no non-interactive discovery path.

Add a `--list` flag to `apify create` that fetches the existing manifest
(via `@apify/actor-templates`, which is already a dependency and already
imported for the interactive picker) and prints one line per template
in the form `<id>\t<language>\t<description>`. When combined with the
existing `--json` support (opted in via `enableJsonFlag`), the command
emits a machine-parseable JSON object with `templates: [{id, label,
category, description}, ...]`. The list path returns early before any
actor-name validation or filesystem work, so it can be invoked from any
directory without side effects.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants