Skip to main content

CLI Reference

Complete command-line interface reference for Petk. This document provides detailed information about all available commands, options, and usage patterns based on the current implementation status.

Global Options​

These options are available for all Petk commands:

OptionShortDescription
--help-hShow help information
--version-VDisplay version number
--verbose-vEnable verbose output
--quiet-qSuppress non-error output
--config <file>-cSpecify configuration file

Implemented Commands​

petk process​

Status: ✅ Fully Implemented

Process template files with Petk directives using the template engine.

Syntax:

petk process [options] <input> [output]

Arguments:

  • <input> - Input file or directory to process
  • [output] - Output file or directory (optional, defaults to stdout or input location)

Options:

OptionDescriptionDefault
--output <path>Specify output locationSame as input
--format <type>Output format (markdown, html, text)markdown
--recursiveProcess directories recursivelyfalse
--watchWatch for file changes and reprocessfalse
--include <pattern>Include files matching pattern**/*.md
--exclude <pattern>Exclude files matching patternnode_modules/**

Template Engine Features:

  • Variable Substitution: Replace {{variable}} with values from config or CLI
  • Include Blocks: Embed content from other files using code blocks with {petk:include} directive
  • Conditional Blocks: Show/hide content based on conditions
  • Loop Blocks: Repeat content for arrays of data
  • Advanced Glob Patterns: Complex file inclusion with sorting options
  • Deterministic Sampling: Consistent random file selection
  • Recursive Resolution: Handle nested includes with cycle detection

Examples:

# Process a single file
petk process template.md

# Process with specific output
petk process input.md output.md

# Process directory recursively
petk process ./templates/ --recursive

# Watch for changes
petk process template.md --watch

# Custom file patterns
petk process ./docs/ --include "**/*.{md,mdx}" --exclude "**/draft/**"

petk convert​

Status: ✅ Fully Implemented

Convert Markdown files to YAML or JSON format using the advanced converter.

Syntax:

petk convert [options] <input> <output>

Arguments:

  • <input> - Input file to convert
  • <output> - Output file path

Options:

OptionDescriptionDefault
--from <format>Source format (auto-detected if not specified)auto
--to <format>Target format (inferred from output extension if not specified)auto
--schema <file>YAML schema validation fileNone
--preserve-structureMaintain original file structure in conversiontrue

Converter Features:

  • Intelligent Parsing: Advanced Markdown AST analysis
  • Multimodal Detection: Automatic detection of code blocks, tables, lists, and media
  • Structure Preservation: Maintains document hierarchy and relationships
  • Schema Validation: Optional YAML schema validation
  • Error Recovery: Robust error handling with detailed diagnostics
  • Metadata Extraction: Extracts frontmatter and document properties

Supported Formats:

  • markdown (.md, .markdown) - Input format
  • yaml (.yml, .yaml) - Output format
  • json (.json) - Output format

Examples:

# Convert Markdown to YAML
petk convert document.md document.yaml

# Convert with explicit formats
petk convert --from markdown --to yaml input.md output.yml

# Convert with schema validation
petk convert data.md data.yaml --schema schema.json

Planned Commands​

The following commands are planned for future releases but not yet implemented:

petk init​

Status: 🚧 Planned

Initialize a new Petk project or configuration.

Note: This command is currently a placeholder. Implementation is planned for future releases.

petk validate​

Status: 🚧 Planned

Validate template files and configuration.

Note: This command is currently a placeholder. Implementation is planned for future releases.

petk serve​

Status: 🚧 Planned

Start a development server with live reload.

Note: This command is currently a placeholder. Implementation is planned for future releases.

Configuration​

Configuration File​

Petk looks for configuration in the following files (in order):

  1. petk.config.js
  2. petk.config.json
  3. .petkrc
  4. petk field in package.json

Configuration Options​

// petk.config.js
module.exports = {
// Input/output configuration
input: './src',
output: './dist',

// Processing options
recursive: true,
include: ['**/*.md', '**/*.mdx'],
exclude: ['**/node_modules/**', '**/draft/**'],

// Template engine settings
engine: {
syntax: 'petk',
variables: {
site: {
title: 'My Site',
url: 'https://example.com'
}
}
},

// Output formatting
format: {
type: 'markdown',
preserveLineBreaks: true,
trimWhitespace: true
}
};

Environment Variables​

VariableDescriptionDefault
PETK_CONFIGPath to configuration fileAuto-discover
PETK_LOG_LEVELLog level (debug, info, warn, error)info
PETK_CACHE_DIRCache directory location~/.petk/cache
PETK_NO_COLORDisable colored outputfalse

Exit Codes​

CodeDescription
0Success
1General error
2Configuration error
3Input/output error
4Validation error
5Template processing error

Advanced Usage​

Template Processing Examples​

Basic Variable Substitution:

# Welcome to {{site.title}}

This site is hosted at {{site.url}}.

File Inclusion:

<!-- Include entire file -->
```{petk:include}
path: shared/header.md
path: templates/card.md
title: My Card
content: Card content

**Complex Glob Patterns:**
```markdown
<!-- Include all markdown files, sorted by last modified -->
```{petk:include}
glob: posts/**/*.md
order_by: last_updated_desc
limit: 10

### Conversion Examples

**Markdown to YAML Conversion:**
```bash
# Convert blog post to structured data
petk convert blog-post.md blog-post.yaml

# Convert with custom schema validation
petk convert content.md output.yaml --schema content-schema.json

Integration with Build Tools​

# NPM scripts integration
npm run build:docs && petk process ./docs/ --output ./public/docs/

# Process templates then convert to YAML
petk process src/templates/ --output temp/ && petk convert temp/*.md dist/

Implementation Status​

CommandStatusCore FeaturesAdvanced Features
process✅ CompleteTemplate processing, variable substitutionAdvanced globbing, deterministic sampling
convert✅ CompleteMarkdown to YAML/JSON conversionMultimodal detection, schema validation
init🚧 PlannedProject initializationTemplate selection
validate🚧 PlannedTemplate validationSchema validation
serve🚧 PlannedDevelopment serverLive reload

Troubleshooting​

Common Issues​

Template Processing Errors:

  • Ensure all included files exist and are accessible
  • Check for circular include dependencies
  • Verify variable names and syntax

Conversion Errors:

  • Validate input Markdown syntax
  • Check file permissions for input/output files
  • Ensure output directory exists

For additional help:

Development Status​

Petk is actively developed with a focus on prompt engineering workflows. The core template processing and conversion functionality is complete and production-ready. Additional commands and features are planned based on user feedback and requirements.