Skip to main content

Crate cliclack_file_autocompletion

Crate cliclack_file_autocompletion 

Source
Expand description

§cliclack-file-autocompletion

File path autocompletion for cliclack prompts.

§Usage

Add to Cargo.toml:

[dependencies]
cliclack = "0.5"
cliclack-file-autocompletion = "0.1"

§Simple

use cliclack_file_autocompletion::FileAutocompleteExt;

let path: String = cliclack::input("Pick a file")
    .file_autocomplete()
    .interact()?;

§With settings

use cliclack_file_autocompletion::{FileAutocompleteExt, FileSettings};

let path: String = cliclack::input("Pick a file or folder")
    .file_autocomplete_with(FileSettings {
        allow_folders: true,
        show_hidden: true,
        ..Default::default()
    })
    .interact()?;

§Extension filter

use cliclack_file_autocompletion::{FileSuggest, FileSettings};

let path: String = cliclack::input("Pick a .rs file")
    .autocomplete(FileSuggest::new(".").with_settings(FileSettings {
        extensions: Some(vec!["rs".into()]),
        ..Default::default()
    }))
    .interact()?;

§Custom root

use cliclack_file_autocompletion::FileSuggest;

let path: String = cliclack::input("Pick a file")
    .autocomplete(FileSuggest::new("/home"))
    .interact()?;

§Behaviour

  • ~ and $ENV_VARS in typed paths are expanded automatically.
  • Relative paths resolve against the configured root (default: .).
  • Absolute paths bypass the root.
  • Folders appear in suggestions only once the user starts typing a fragment — listing a directory shows files only.
  • allow_folders / allow_files are enforced at submission via validation, not by hiding entries during navigation.
  • Hidden files (.dotfiles) are hidden by default; enable with show_hidden: true.

§Running the example

cargo run --example basic

Structs§

FileSettings
Controls which filesystem entries are shown and accepted.
FileSuggest
A cliclack::Suggest implementation that reads the filesystem.

Traits§

FileAutocompleteExt
Extension methods on cliclack::Input for file path autocompletion.