ardent 0.1.0

Opinionated formatter for NSIS scripts
Documentation

ardent

An opinionated code formatter for NSIS scripts

Installation

crates.io

cargo install ardent

Source

git clone https://github.com/idleberg/ardent.git
cd ardent
cargo build --release

The binary is at target/release/ardent.

CLI Usage

ardent [OPTIONS] [COMMAND]

Commands:
  format  Format NSIS scripts
  check   Check if NSIS scripts are formatted correctly

Options:
  -D, --debug    Print debug messages
  -h, --help     Print help
  -V, --version  Print version

Format

Formats one or more .nsi / .nsh files.

# Print formatted output to stdout
ardent format installer.nsi

# Edit files in-place
ardent format --write src/**/*.nsi

See ardent format --help for available options.

Check

Checks whether files are already formatted.

# Check only (reports drift)
ardent check src/**/*.nsi

# Check and auto-fix (still exits 1 if drift was found)
ardent check --write src/**/*.nsi

See ardent check --help for available options.

Library Usage

Formatting

use ardent::{DentOptions, EndOfLines, Formatter};

let formatter = Formatter::new(DentOptions {
    end_of_lines: Some(EndOfLines::Lf),
    use_tabs: true,
    indent_size: 2,
    trim_empty_lines: true,
}).expect("valid options");

let input = r#"section "My Section"
detailprint "Hello"
sectionend
"#;

let output = formatter.format(input).expect("valid NSIS");
assert_eq!(output, "Section \"My Section\"\n\tDetailPrint \"Hello\"\nSectionEnd\n");

Checking

Returns None if the input is already formatted, or Some(formatted) if it needs changes.

use ardent::{DentOptions, Formatter};

let formatter = Formatter::new(DentOptions::default()).unwrap();

match formatter.check(input).unwrap() {
    None => println!("Already formatted"),
    Some(formatted) => println!("Needs formatting"),
}

Options

Field Type Default Description
end_of_lines Option<EndOfLines> None (auto-detect) Force CRLF or LF line endings
indent_size usize 2 Spaces per indent level (ignored when using tabs)
trim_empty_lines bool true Collapse consecutive blank lines and strip leading/trailing blanks
use_tabs bool true Indent with tabs instead of spaces

:white_check_mark: Why defaulting to tabs is good for accessibility

License

This work is licensed under The MIT License.