MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / load_from_directory

Method load_from_directory

crates/opencode-command/src/lib.rs:119–150  ·  view source on GitHub ↗

Load commands from .opencode/commands directory

(&mut self, project_dir: &Path)

Source from the content-addressed store, hash-verified

117
118 /// Load commands from .opencode/commands directory
119 pub fn load_from_directory(&mut self, project_dir: &Path) -> anyhow::Result<()> {
120 let commands_dir = project_dir.join(".opencode/commands");
121
122 if !commands_dir.exists() {
123 return Ok(());
124 }
125
126 let pattern = commands_dir.join("*.md");
127 let pattern_str = pattern.to_string_lossy();
128
129 for entry in glob::glob(&pattern_str)? {
130 let path = entry?;
131 let name = path
132 .file_stem()
133 .and_then(|s| s.to_str())
134 .unwrap_or("unknown")
135 .to_string();
136
137 let template = std::fs::read_to_string(&path)?;
138 let description = extract_description(&template)
139 .unwrap_or_else(|| format!("Custom command: {}", name));
140
141 self.register(Command {
142 name: name.clone(),
143 description,
144 template,
145 source: CommandSource::File(path),
146 });
147 }
148
149 Ok(())
150 }
151
152 pub fn parse(&self, input: &str) -> Option<(&Command, Vec<String>)> {
153 let input = input.trim_start();

Callers 1

run_non_interactiveFunction · 0.45

Calls 4

extract_descriptionFunction · 0.85
existsMethod · 0.80
registerMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected