Docs
/
/

Partials

Commands for managing partials in the Knock CLI.

#

Partial commands enable you to manage partials in your Knock account from the CLI.

Partial file structure

#

When partials are pulled from Knock, they are stored in directories named by their partial key. Each partial directory contains a partial.json file that describes the partial's properties, and a content file based on the partial's type (HTML, markdown, plaintext, or JSON).

The content file name depends on the partial's type:

  • HTML partials: content.html
  • Markdown partials: content.md
  • Plaintext partials: content.txt
  • JSON partials: content.json

If you're migrating your local partial files into Knock, you can arrange them using the example file structure above and then push them into Knock with a single command using knock partial push --all.

knock partial list [flags]

#

List all partials in the environment. Use an --environment flag to specify the target environment; if omitted, the Knock CLI uses the account's default environment.

Flags

--environmentstring

The environment to use. When omitted, the account's default environment is used.

--branchstring

The branch to use. Defaults to the main branch.

--hide-uncommitted-changesboolean

Should any uncommitted changes be hidden? Defaults to false.

--limitnumber

The total number to fetch per page.

--afterstring

Fetches all entries after this cursor.

--beforestring

Fetches all entries before this cursor.

--jsonstring

Format output as json.

knock partial new [flags]

#

Create a new partial with a minimal configuration.

The command will create a new partial directory in your local file system. By default, this will be in the partials resource directory set by your knock.json file, or the current working directory if not configured.

Flags

--keystring

The key for the partial. If not provided, will be prompted or inferred from the partial directory name.

--namestring

The name for the partial. If not provided, will be generated from the key.

--typestring

The type of partial to create. One of: html, markdown, text, json.

--environmentstring

The environment to use. When omitted, the account's default environment is used.

--branchstring

The branch to use. Defaults to the main branch.

--pushboolean

Push the partial to Knock after creating it locally. Defaults to false.

--templatestring

A template to use for scaffolding the partial. Accepts a template string that resolves to a GitHub repository URL. For example, <your-org>/<your-repo>/partials/my-partial. Use partials/<partial-key> to reference pre-built Knock templates. You cannot use this flag with --type.

--forceboolean

Overwrites an existing partial directory without prompting for confirmation. Defaults to false.

knock partial get <partial_key> [flags]

#

You can show more details about a given partial with the partial get command, followed by the target partial key.

Use an --environment flag to specify the target environment; if omitted, the Knock CLI uses the account's default environment.

Flags

--environmentstring

The environment to use. When omitted, the account's default environment is used.

--branchstring

The branch to use. Defaults to the main branch.

--hide-uncommitted-changesboolean

Should any uncommitted changes be hidden? Defaults to false.

--jsonstring

Format output as json.

knock partial pull <partial_key> [flags]

#

You can pull and download partial files from Knock to a local file system with the partial pull command. Knock CLI will create a new partial directory or update the existing partial directory in the local file system.

By default this command will resolve to the partial resource directory via your knock.json file. When not set, will use the current working directory as the default. In the case of the --all flag, the target directory path will be resolved via your knock.json file or the --partials-dir flag.

Note: if pulling the target partial for the first time (or all partials), Knock CLI will ask to confirm before writing to the local file system.

See the Partial file structure section for details on how partial files are organized.

Flags

--environmentstring

The environment to use. When omitted, the account's default environment is used.

--branchstring

The branch to use. Defaults to the main branch.

--allboolean

Whether to pull all partials from the specified environment into the target directory path set by --partials-dir. Defaults to false.

Note: all contents in the target directory will be erased and replaced with all partials from the specified environment.

--partials-dirdirectory

Specifies which target directory path to pull all partials into. Only available to be used with --all, and defaults to the current working directory.

--hide-uncommitted-changesboolean

Should any uncommitted changes be hidden? Defaults to false.

--forceboolean

Removes the confirmation prompt. Defaults to false.

knock partial push <partial_key> [flags]

#

You can push and upload a partial directory to Knock with the partial push command. Knock will update an existing partial by the matching partial key, or create a new partial if it does not exist yet.

By default this command will resolve to the partial resource directory via your knock.json file. When not set, will use the current working directory as the default. In the case of the --all flag, the target directory path will be resolved via your knock.json file or the --partials-dir flag.

Note:

  • You must be directly above the target partial directory when running the partial push command, so the CLI can locate the partial.json file.
  • You can also pass in the --commit flag (with an optional --commit-message flag) to commit the upserted changes immediately.
  • You can pass --allow-empty with --commit to create an empty commit when re-upserting an unchanged resource. See empty commits for more on when and why to use this.

Flags

--environmentstring

The environment to use. When omitted, the account's default environment is used.

--commitboolean

Push and commit at the same time. Defaults to false.

--branchstring

The branch to use. Defaults to the main branch.

-m, --commit-messagestring

The commit message to pass when using the --commit flag.

--allow-emptyboolean

Only meaningful with --commit. When the resource is already published with no unpublished changes, create an empty commit instead of a no-op publish. Defaults to false.

--allboolean

Whether to push all partial files to the target environment. Defaults to false.

--partials-dirdirectory

Specifies the target directory path to find and push all partials from. Only available to be used with --all, and defaults to the current working directory.

--forceboolean

Force pushes the resource or resources to Knock, overwriting whatever is currently stored. If you're using this on a non-development environment, you should also ensure you commit the changes. Defaults to false.

knock partial validate <partial_key> [flags]

#

Validates one or more partial files. Useful for checking if the file is valid before running the partial push method.

Flags

--environmentstring

The environment to use. When omitted, the account's default environment is used.

--branchstring

The branch to use. Defaults to the main branch.

--allboolean

Whether to validate all partial files. Defaults to false.

--partials-dirdirectory

Specifies the target directory path to find and validate all partial files from. Only available to be used with --all, and defaults to the current working directory.

knock partial open <partial_key> [flags]

#

Open a partial in the Knock dashboard. This command opens the partial page in your default browser.

Flags

--environmentstring

The environment to use. When omitted, the account's default environment is used.

--branchstring

The branch to use. Defaults to the main branch.

knock partial archive <partial_key> [flags]

#

Archive a partial in every environment. Archiving frees the partial's key, so a new partial can use it. To restore it, unarchive the partial.

If a local copy of the partial exists in <knock dir>/partials/<partial_key>, or in the directory you pass with --partials-dir, the command removes that directory so a later push doesn't create the partial again. Any changes in it that you haven't pushed are lost.

If you've enabled environments and you're working on a branch, exit the branch with knock branch exit first. Archiving can't run on a branch, and the command exits with an error.

The command asks you to confirm before it archives. Pass --force to skip the prompt. You must pass it when you use --json or run the command outside an interactive terminal, such as in CI. Otherwise the command exits with an error.

Flags

--environmentstringRequired

The environment to run the command in. The partial is archived in every environment.

--partials-dirstring

The directory to look in for a local copy of the partial. Defaults to the partials directory in your knock dir.

--forceboolean

Skips the confirmation prompt. Required when using --json or running outside an interactive terminal. The command still removes a local copy of the partial if it finds one. Defaults to false.

--jsonboolean

Format output as json. The output includes local_dir_removed, the path of the local directory the command removed, when it removed one.

knock partial unarchive <partial_key> [flags]

#

Restore an archived partial by its original key. Unarchiving restores the partial in every environment it was archived from. If the key was archived more than once, the command restores the most recent archive.

If a live partial uses the same key, archive it before you unarchive the archived one.

Unarchiving doesn't create a local copy. Pull the partial to get one.

If you've enabled environments and you're working on a branch, exit the branch with knock branch exit first. Unarchiving can't run on a branch, and the command exits with an error.

Flags

--environmentstringRequired

The environment to run the command in. The partial is restored in every environment it was archived from.

--jsonboolean

Format output as json.

knock partial discard <partial_key> [flags]

#

Discard the uncommitted changes to a partial, returning it to its last committed version. The command changes only the environment or branch you pass.

The command asks you to confirm before it discards. Pass --force to skip the prompt. You must pass it when you use --json or run the command outside an interactive terminal, such as in CI. Otherwise the command exits with an error.

Flags

--environmentstringRequired

The environment to discard changes in.

--branchstring

The branch to use. Defaults to the main branch.

--forceboolean

Skips the confirmation prompt. Required when using --json or running outside an interactive terminal. Defaults to false.

--jsonboolean

Format output as json.

New chat