Skip to main content

upsert_managed_block

Function upsert_managed_block 

Source
pub fn upsert_managed_block(
    bin_name: &str,
    shell: Shell,
    file_path: &Path,
    block_body: &str,
) -> Result<()>
Expand description

Inserts or replaces a managed shell configuration block in a startup file.

The managed block is identified by the binary name and shell, allowing repeat installs to update the same block instead of appending duplicates. Existing startup files are backed up before being modified.

§Arguments

  • bin_name: Binary name used in the managed block markers.
  • shell: Shell whose startup block is being inserted or replaced.
  • file_path: Startup file to update.
  • block_body: Shell-specific content placed between the managed markers.

§Returns

Returns Ok(()) after the startup file has been written.

§Examples

use std::fs;
use clap_complete::aot::Shell;
use rust_config_tree::upsert_managed_block;

let path = std::env::temp_dir().join("rust-config-tree-upsert-doctest.rc");
upsert_managed_block("myapp", Shell::Bash, &path, "body\n")?;

let content = fs::read_to_string(&path)?;
assert!(content.contains("# >>> myapp bash completions >>>"));
assert!(content.contains("body"));