CLI: convert node commands to typed async API
- node.rs: use memory::* typed helpers instead of memory_rpc() - main.rs: make Run trait async, await all command dispatch - defs.rs: bridge get_group_content async via block_in_place Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
933221f482
commit
fa50f1c826
3 changed files with 84 additions and 102 deletions
46
src/main.rs
46
src/main.rs
|
|
@ -384,43 +384,43 @@ fn print_help() {
|
|||
// ── Dispatch ─────────────────────────────────────────────────────────
|
||||
|
||||
trait Run {
|
||||
fn run(self) -> Result<(), String>;
|
||||
async fn run(self) -> Result<(), String>;
|
||||
}
|
||||
|
||||
impl Run for Command {
|
||||
fn run(self) -> Result<(), String> {
|
||||
async fn run(self) -> Result<(), String> {
|
||||
match self {
|
||||
Self::Search { keys } => cli::node::cmd_search(&keys),
|
||||
Self::Render { key } => cli::node::cmd_render(&key),
|
||||
Self::Write { key } => cli::node::cmd_write(&key),
|
||||
Self::Edit { key } => cli::node::cmd_edit(&key),
|
||||
Self::History { full, key } => cli::node::cmd_history(&key, full),
|
||||
Self::Search { keys } => cli::node::cmd_search(&keys).await,
|
||||
Self::Render { key } => cli::node::cmd_render(&key).await,
|
||||
Self::Write { key } => cli::node::cmd_write(&key).await,
|
||||
Self::Edit { key } => cli::node::cmd_edit(&key).await,
|
||||
Self::History { full, key } => cli::node::cmd_history(&key, full).await,
|
||||
Self::Tail { n, full, provenance, all_versions }
|
||||
=> cli::journal::cmd_tail(n, full, provenance.as_deref(), !all_versions),
|
||||
Self::Status => cli::admin::cmd_status(),
|
||||
Self::Query { expr } => cli::node::cmd_query(&expr),
|
||||
Self::WeightSet { key, weight } => cli::node::cmd_weight_set(&key, weight),
|
||||
Self::Node(sub) => sub.run(),
|
||||
Self::Journal(sub) => sub.run(),
|
||||
Self::GraphCmd(sub) => sub.run(),
|
||||
Self::Agent(sub) => sub.run(),
|
||||
Self::Admin(sub) => sub.run(),
|
||||
Self::Query { expr } => cli::node::cmd_query(&expr).await,
|
||||
Self::WeightSet { key, weight } => cli::node::cmd_weight_set(&key, weight).await,
|
||||
Self::Node(sub) => sub.run().await,
|
||||
Self::Journal(sub) => sub.run().await,
|
||||
Self::GraphCmd(sub) => sub.run().await,
|
||||
Self::Agent(sub) => sub.run().await,
|
||||
Self::Admin(sub) => sub.run().await,
|
||||
// mcp-schema moved to consciousness-mcp binary
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Run for NodeCmd {
|
||||
fn run(self) -> Result<(), String> {
|
||||
async fn run(self) -> Result<(), String> {
|
||||
match self {
|
||||
Self::Delete { key } => cli::node::cmd_node_delete(&key),
|
||||
Self::Rename { old_key, new_key } => cli::node::cmd_node_rename(&old_key, &new_key),
|
||||
Self::Delete { key } => cli::node::cmd_node_delete(&key).await,
|
||||
Self::Rename { old_key, new_key } => cli::node::cmd_node_rename(&old_key, &new_key).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Run for JournalCmd {
|
||||
fn run(self) -> Result<(), String> {
|
||||
async fn run(self) -> Result<(), String> {
|
||||
match self {
|
||||
Self::Write { name, text } => cli::journal::cmd_journal_write(&name, &text),
|
||||
Self::Tail { n, full, level } => cli::journal::cmd_journal_tail(n, full, level),
|
||||
|
|
@ -429,7 +429,7 @@ impl Run for JournalCmd {
|
|||
}
|
||||
|
||||
impl Run for GraphCmd {
|
||||
fn run(self) -> Result<(), String> {
|
||||
async fn run(self) -> Result<(), String> {
|
||||
match self {
|
||||
Self::Link { key } => cli::graph::cmd_link(&key),
|
||||
Self::LinkAdd { source, target, reason }
|
||||
|
|
@ -446,7 +446,7 @@ impl Run for GraphCmd {
|
|||
}
|
||||
|
||||
impl Run for AgentCmd {
|
||||
fn run(self) -> Result<(), String> {
|
||||
async fn run(self) -> Result<(), String> {
|
||||
match self {
|
||||
Self::Run { agent, count, target, query, dry_run, local, state_dir }
|
||||
=> cli::agent::cmd_run_agent(&agent, count, &target, query.as_deref(), dry_run, local, state_dir.as_deref()),
|
||||
|
|
@ -455,7 +455,7 @@ impl Run for AgentCmd {
|
|||
}
|
||||
|
||||
impl Run for AdminCmd {
|
||||
fn run(self) -> Result<(), String> {
|
||||
async fn run(self) -> Result<(), String> {
|
||||
match self {
|
||||
Self::Init => cli::admin::cmd_init(),
|
||||
Self::Health => cli::admin::cmd_health(),
|
||||
|
|
@ -465,7 +465,7 @@ impl Run for AdminCmd {
|
|||
Self::DailyCheck => cli::admin::cmd_daily_check(),
|
||||
Self::Import { files } => cli::admin::cmd_import(&files),
|
||||
Self::Export { files, all } => cli::admin::cmd_export(&files, all),
|
||||
Self::LoadContext { stats } => cli::node::cmd_load_context(stats),
|
||||
Self::LoadContext { stats } => cli::node::cmd_load_context(stats).await,
|
||||
Self::MigrateTranscriptProgress => {
|
||||
let mut store = store::Store::load()?;
|
||||
let count = store.migrate_transcript_progress()?;
|
||||
|
|
@ -496,7 +496,7 @@ async fn main() {
|
|||
|
||||
let cli = Cli::parse();
|
||||
|
||||
if let Err(e) = cli.command.run() {
|
||||
if let Err(e) = cli.command.run().await {
|
||||
eprintln!("Error: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue