MCPcopy Create free account
hub / github.com/douglance/devsql / engine_from_options

Function engine_from_options

crates/devsql/src/tools/mod.rs:21–59  ·  view source on GitHub ↗

Create an engine from common options (repo, data_dir). Returns `(engine, repo_path)` on success, or a `CommandResult::Error` on failure.

(
    options: &serde_json::Value,
)

Source from the content-addressed store, hash-verified

19///
20/// Returns `(engine, repo_path)` on success, or a `CommandResult::Error` on failure.
21pub fn engine_from_options(
22 options: &serde_json::Value,
23) -> Result<(UnifiedEngine, PathBuf), CommandResult> {
24 let repo_str = options
25 .get("repo")
26 .and_then(|v| v.as_str())
27 .unwrap_or(".");
28
29 let repo_path = if repo_str == "." {
30 std::env::current_dir().map_err(|e| CommandResult::Error {
31 code: "PATH_ERROR".into(),
32 message: format!("Cannot determine current directory: {e}"),
33 retryable: false,
34 exit_code: Some(1),
35 cta: None,
36 })?
37 } else {
38 PathBuf::from(repo_str)
39 };
40
41 let claude_dir = match options.get("data_dir").and_then(|v| v.as_str()) {
42 Some(d) => PathBuf::from(d),
43 None => dirs::home_dir()
44 .unwrap_or_else(|| PathBuf::from("."))
45 .join(".claude"),
46 };
47
48 let engine = UnifiedEngine::new(claude_dir, repo_path.clone()).map_err(|e| {
49 CommandResult::Error {
50 code: "ENGINE_ERROR".into(),
51 message: format!("Failed to create engine: {e}"),
52 retryable: false,
53 exit_code: Some(1),
54 cta: None,
55 }
56 })?;
57
58 Ok((engine, repo_path))
59}

Callers 4

runMethod · 0.85
runMethod · 0.85
runMethod · 0.85
runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected