MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / add_paths

Method add_paths

crates/chat-cli/src/cli/chat/context.rs:132–159  ·  view source on GitHub ↗

Add paths to the context configuration. # Arguments `paths` - List of paths to add `force` - If true, skip validation that the path exists # Returns A Result indicating success or an error

(&mut self, os: &Os, paths: Vec<String>, force: bool)

Source from the content-addressed store, hash-verified

130 /// # Returns
131 /// A Result indicating success or an error
132 pub async fn add_paths(&mut self, os: &Os, paths: Vec<String>, force: bool) -> Result<()> {
133 // Validate paths exist before adding them
134 if !force {
135 let mut context_files = Vec::new();
136
137 // Check each path to make sure it exists or matches at least one file
138 for path in &paths {
139 // We're using a temporary context_files vector just for validation
140 // Pass is_validation=true to ensure we error if glob patterns don't match any files
141 match process_path(os, path, &mut context_files, true).await {
142 Ok(_) => {}, // Path is valid
143 Err(e) => return Err(eyre!("Invalid path '{}': {}. Use --force to add anyway.", path, e)),
144 }
145 }
146 }
147
148 for path in paths {
149 if self.paths.iter().any(|p| p == path.as_str()) {
150 return Err(eyre!("Rule '{}' already exists.", path));
151 }
152
153 // The assumption here is that we are only calling [add_paths] for adding paths in
154 // session
155 self.paths.push(ContextFilePath::Session(path));
156 }
157
158 Ok(())
159 }
160
161 /// Remove paths from the context configuration.
162 ///

Callers 3

test_path_opsFunction · 0.80
executeMethod · 0.80

Calls 2

process_pathFunction · 0.85
as_strMethod · 0.45

Tested by 2

test_path_opsFunction · 0.64