Skip to main content

execute

Function execute 

Source
pub fn execute(args: &AddArgs) -> Result<(), String>
Expand description

Execute the add command.

This generates UI window files based on validated inputs.

§Process

  1. Detect project: Validates this is a Dampen project
  2. Validate name: Checks window name is valid identifier
  3. Resolve path: Determines output directory (default or custom)
  4. Generate files: Creates .rs and .dampen files from templates
  5. Report success: Shows file paths and next steps

§Errors

Returns Err(String) if:

  • Not in a Dampen project (no dampen-core in Cargo.toml)
  • Window name is invalid (empty, starts with number, reserved keyword)
  • Output path is invalid (absolute, escapes project)
  • Files already exist (prevents overwriting)
  • I/O errors occur during file creation

§Examples

use dampen_cli::commands::add::{AddArgs, execute};

let args = AddArgs {
    ui: Some("settings".to_string()),
    path: None,
    no_integrate: false,
};

match execute(&args) {
    Ok(()) => println!("Window created successfully"),
    Err(e) => eprintln!("Error: {}", e),
}