A comprehensive guide on writing YAML files to define glazed commands
This guide explains how to write YAML files to define commands in the Glazed framework. YAML configuration provides a declarative way to create commands without writing Go code.
A basic YAML command file contains these essential elements:
name: command-name
short: Short description of the command
long: |
A longer description that can span
multiple lines and provide more detail
flags:
- name: flag-name
type: string
help: Description of the flag
arguments:
- name: arg-name
type: string
required: true
help: Description of the argument
Glazed supports these field types for both flags and arguments:
string: Text valuesint: Integer valuesfloat: Floating-point numbersbool: Boolean true/false valuesdate: Date valueschoice: Single selection from predefined choiceschoiceList: Multiple selections from predefined choicesstringList: List of stringsintList: List of integersfloatList: List of floating-point numbersfile: Single file input, provides detailed file metadata and contentfileList: List of files with metadata and contentstringFromFile: Load string content from a file (prefix with @)stringFromFiles: Load string content from multiple filesstringListFromFile: Load list of strings from a filestringListFromFiles: Load list of strings from multiple filesobjectFromFile: Load and parse structured data from a fileobjectListFromFile: Load and parse list of objects from a fileobjectListFromFiles: Load and parse lists of objects from multiple fileskeyValue: Parse key-value pairs from string (comma-separated) or file (with @ prefix)Flags are optional fields that modify command behavior. Here's a comprehensive example:
flags:
- name: output-format
shortFlag: f # Optional short form
type: string
default: "json"
help: "Output format (json, yaml, or table)"
choices: ["json", "yaml", "table"]
required: false
- name: limit
type: int
default: 10
help: "Maximum number of items to process"
- name: tags
type: stringList
help: "List of tags to filter by"
default: ["default"]
name: The flag name (required)shortFlag: Optional single-character aliastype: Field type (required)default: Default value if flag is not specifiedhelp: Help text describing the flagchoices: List of valid valuesrequired: Whether the flag must be specifiedArguments are positional fields. They're defined similarly to flags:
arguments:
- name: source
type: file
help: "Source file to process"
required: true
- name: destinations
type: stringList
help: "List of destination paths"
default: ["./output"]
Arguments support the same properties as flags, except for shortFlag.
Sections help organize related fields. Define sections in your YAML:
sections:
- name: Output Configuration
slug: output
description: "Configure output formatting"
prefix: "output-"
flags:
- name: format
type: string
default: "json"
- name: pretty
type: bool
default: true
- name: Processing Options
slug: processing
description: "Control processing behavior"
flags:
- name: threads
type: int
default: 4
Naming Conventions
Organization
Validation
choices to restrict valid valuesname: list-items
short: List items from database
flags:
- name: limit
type: int
default: 10
help: Maximum number of items to return
- name: format
type: string
default: table
choices: [table, json, yaml]
help: Output format
name: process-data
short: Process data files with multiple options
sections:
- name: Input Options
slug: input
flags:
- name: source
type: file
required: true
help: Source data file
- name: format
type: string
default: csv
choices: [csv, json, xml]
help: Input file format
- name: Processing Options
slug: processing
flags:
- name: batch-size
type: int
default: 1000
help: Number of records to process at once
- name: threads
type: int
default: 4
help: Number of processing threads
- name: Output Options
slug: output
flags:
- name: destination
type: directory
required: true
help: Output directory
- name: compress
type: bool
default: false
help: Compress output files
YAML command files provide a powerful way to define Glazed commands declaratively. By following these guidelines and patterns, you can create clear, maintainable, and user-friendly command definitions that take full advantage of Glazed's capabilities.