Skip to content

Commit 24ca19f

Browse files
committed
Docstrings
1 parent 6ab0c1c commit 24ca19f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

codex-rs/tui/src/bottom_pane/prompt_args.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ use shlex::Shlex;
55
use std::collections::HashMap;
66
use std::collections::HashSet;
77

8-
static PROMPT_ARG_REGEX: Lazy<Regex> = Lazy::new(|| {
9-
// Regex is a hard-coded literal; abort if it ever fails to compile.
10-
Regex::new(r"\$[A-Z][A-Z0-9_]*").unwrap_or_else(|_| std::process::abort())
11-
});
8+
static PROMPT_ARG_REGEX: Lazy<Regex> =
9+
Lazy::new(|| Regex::new(r"\$[A-Z][A-Z0-9_]*").unwrap_or_else(|_| std::process::abort()));
1210

1311
#[derive(Debug)]
1412
pub enum PromptArgsError {
@@ -55,6 +53,11 @@ impl PromptExpansionError {
5553
}
5654
}
5755

56+
/// Extracts the unique placeholder variable names from a prompt template.
57+
///
58+
/// A placeholder is any token that matches the pattern `$[A-Z][A-Z0-9_]*`
59+
/// (for example `$USER`). The function returns the variable names without
60+
/// the leading `$`, de-duplicated and in the order of first appearance.
5861
pub fn prompt_argument_names(content: &str) -> Vec<String> {
5962
let mut seen = HashSet::new();
6063
let mut names = Vec::new();
@@ -68,6 +71,11 @@ pub fn prompt_argument_names(content: &str) -> Vec<String> {
6871
names
6972
}
7073

74+
/// Parses the `key=value` pairs that follow a custom prompt name.
75+
///
76+
/// The input is split using shlex rules, so quoted values are supported
77+
/// (for example `USER="Alice Smith"`). The function returns a map of parsed
78+
/// arguments, or an error if a token is missing `=` or if the key is empty.
7179
pub fn parse_prompt_inputs(rest: &str) -> Result<HashMap<String, String>, PromptArgsError> {
7280
let mut map = HashMap::new();
7381
if rest.trim().is_empty() {
@@ -86,6 +94,11 @@ pub fn parse_prompt_inputs(rest: &str) -> Result<HashMap<String, String>, Prompt
8694
Ok(map)
8795
}
8896

97+
/// Expands a message of the form `/name key=value …` using a matching saved prompt.
98+
///
99+
/// If the text does not start with `/`, or if no prompt named `name` exists,
100+
/// the function returns `Ok(None)`. On success it returns
101+
/// `Ok(Some(expanded))`; otherwise it returns a descriptive error.
89102
pub fn expand_custom_prompt(
90103
text: &str,
91104
custom_prompts: &[CustomPrompt],

0 commit comments

Comments
 (0)