Skip to main content

Module cmd

Module cmd 

Source
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(())
}

Structs§

Cli
A simple CLI struct for building the SSG command.
LanguageCode
Type-safe representation of a language code.
SsgConfig
Core configuration for the static site generator.
SsgConfigBuilder
Builder for SsgConfig.

Enums§

CliError
Possible errors that can occur during CLI operations.

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.
MAX_CONFIG_SIZE
Maximum allowed size in bytes for config files.
RESERVED_NAMES
Reserved names that cannot be used as paths on Windows systems.

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 true if s looks like a valid HTTP(S) URL.
resolve_host
Resolve the dev-server host, preferring $SSG_HOST over DEFAULT_HOST.
resolve_port
Resolve the dev-server port, preferring $SSG_PORT over DEFAULT_PORT.
validate_url
Validates a URL for security and format.