Fn

Function Fn 

Source
pub fn Fn()
Expand description

The main entry point of the run binary.

This function serves as the primary entry point for the run orchestrator. It performs three main steps:

  1. Initialization: Sets up the global logger with appropriate formatting and log level based on the RUST_LOG environment variable.

  2. Argument Parsing: Parses command-line arguments and environment variables using the Argument struct, which includes automatic validation and help text generation.

  3. Orchestration: Delegates to the Process function to execute the complete run orchestration workflow, including:

    • Validating project directory and configuration files
    • Resolving environment variables from profiles
    • Starting the development server with hot-reload
    • Managing watch mode for file changes
    • Executing the run command
    • Handling graceful shutdown

§Behavior

On successful run completion:

  • Logs an informational message: “Run process completed successfully.”
  • Exits with status code 0 (implicit)

On run failure:

  • Logs an error message with the error details
  • Exits with status code 1 via std::process::exit(1)

§Example Invocation

Basic run with debug profile:

cargo run --bin Maintain -- --run --profile debug

Run with hot-reload disabled:

cargo run --bin Maintain -- --run --profile debug --no-hot-reload

Run with custom workbench:

cargo run --bin Maintain -- --run --profile debug --workbench Wind

§Error Handling

The function uses Rust’s question mark operator (?) to propagate errors from the Process function. When an error occurs:

  1. The error is logged with error!() macro
  2. The program exits with status code 1

This ensures that:

  • Run failures are clearly reported
  • The workspace is left in a consistent state

§Logging

The function requires the logger to be initialized first (via Logger()). All subsequent operations use structured logging with targets:

  • Run - General run orchestration messages
  • Run::Process - Process management messages
  • Run::Environment - Environment variable resolution
  • Run::HotReload - Hot-reload related messages

Control log verbosity with RUST_LOG:

export RUST_LOG=debug # More verbose output
export RUST_LOG=error # Only errors

§Thread Safety

This function is not designed to be called concurrently. It should be called exactly once at program startup. The underlying Process function and logging infrastructure handle their own synchronization requirements.

§Implementation Notes

The function name Fn is intentionally short to serve as a concise entry point, following the naming convention of the Build module.

The function does not return a value because it either completes successfully (and the program exits) or exits with an error status. This pattern is common for Rust binaries that serve as command-line tools or development scripts.