Skip to main content

expand_args

Function expand_args 

Source
pub fn expand_args(args: &[String]) -> Vec<String>
Expand description

Expand glob patterns in arguments.

This function expands shell-style glob patterns like *.txt or **/*.rs into a list of matching file paths. Arguments that don’t contain glob patterns or don’t match any files are returned as-is.

§Glob Patterns

  • * matches any sequence of characters except path separators
  • ? matches any single character except path separators
  • ** matches any sequence of characters including path separators
  • [...] matches any character in the brackets
  • [!...] matches any character not in the brackets

§Example

use click::utils::expand_args;

// Assuming *.txt files exist in the current directory
let args = vec!["file.rs".to_string(), "*.txt".to_string()];
let expanded = expand_args(&args);
// Returns ["file.rs", "a.txt", "b.txt", ...] if those files exist

§Reference

Based on Python Click’s utils.py:_expand_args.