Expand description
§Command Line Interface Module
This module provides a secure and robust command-line interface (CLI) for the Static Site Generator (SSG). It handles argument parsing, configuration management, and validation of user inputs to ensure that the static site generator operates reliably and securely.
§Key Features
- Safe path handling (including symbolic link checks and canonicalization)
- Input validation (URL, language, environment variables)
- Secure configuration with size-limited config files
- Builder pattern for convenient configuration construction
- Error handling via
CliError
§Example Usage
use ssg::cmd::{Cli, SsgConfig};
fn main() -> anyhow::Result<()> {
let matches = Cli::build().get_matches();
// Attempt to load configuration from command-line arguments
let mut config = SsgConfig::from_matches(&matches)?;
println!("Configuration loaded: {:?}", config);
// Continue with application logic...
Ok(())
}Modules§
- audit
ssg auditsubcommand handler.- completions
- Shell-completion generation from the live clap definition.
- man
- Man-page generation from the live clap definition.
Structs§
- Cli
- A simple CLI struct for building the SSG command.
- Edge
Headers Config - Edge-runtime header emitter configuration (issue #550). Surfaces
the
[edge_headers]section ofssg.toml: - Image
Config - Image-optimization tunables (issue #521). Surfaces the
[image]section ofssg.toml: - Language
Code - Type-safe representation of a language code.
- Security
Config - Security tunables (v0.0.47 plan §3 item 2.3). Surfaces the
[security]section ofssg.toml: - SsgConfig
- Core configuration for the static site generator.
- SsgConfig
Builder - Builder for
SsgConfig.
Enums§
- CliError
- Possible errors that can occur during CLI operations.
- CliInvocation
- Outcome of
Cli::parse_and_dispatch— tellsmain/runwhich subcommand was selected, or that the legacy form was used. - SriAlgorithm
- Digest algorithm used for Subresource Integrity
integrity=attributes on externalized assets (v0.0.47 plan §3 item 2.3).
Constants§
- DEFAULT_
HOST - Default host for the local development server.
- DEFAULT_
PORT - Default port for the local development server.
- DEFAULT_
SITE_ NAME - Default site name for the configuration.
- DEFAULT_
SITE_ TITLE - Default site title for the configuration — deliberately empty.
- DEPLOY_
TARGETS - Deployment targets accepted by
ssg deploy --target …. - LEGACY_
DEPRECATION_ WARNING - Deprecation message printed to stderr when the legacy flag-only form is used. Kept as a const so tests can assert on the exact text.
- MAX_
CONFIG_ SIZE - Maximum allowed size in bytes for config files.
- RESERVED_
NAMES - Reserved names that cannot be used as paths on Windows systems.
- SUBCOMMANDS
- Subcommand names recognised by the unified CLI. Used to discriminate
between subcommand-style invocations (
ssg dev,ssg build …) and the legacy flag-only form (ssg -s public).
Statics§
- DEFAULT_
CONFIG - A static default configuration for the SSG site.
Functions§
- default_
config - Returns a reference to the lazily-initialised default configuration.
- is_
valid_ url - Returns
trueifslooks like a valid HTTP(S) URL. - resolve_
host - Resolve the dev-server host, preferring
$SSG_HOSToverDEFAULT_HOST. - resolve_
port - Resolve the dev-server port, preferring
$SSG_PORToverDEFAULT_PORT. - validate_
url - Validates a URL for security and format.