use clap::{Parser, Subcommand};
use crate::commands;
pub const EXIT_CODES_HELP: &str = "\
Exit codes:
0 success
1 generic failure (catch-all for non-classified errors)
2 usage error (clap argument-parse failure — unknown flag, bad value)
3 not found (entity / mem / resource missing)
4 hash mismatch (optimistic-locking failure on a mutation)
5 validation / schema / policy refusal
For programmatic branching, prefer `--json` over the exit code:
memstead <subcommand> ... --json | jq -r .code
The JSON envelope's `code` field carries the typed token
(e.g. INVALID_TITLE, HAS_INCOMING_REFS, CROSS_MEM_LINK_NOT_ALLOWED)
with structured recovery details under `.details`.";
#[derive(Parser, Debug)]
#[command(name = "memstead", version, about, long_about = None, after_long_help = EXIT_CODES_HELP)]
pub struct Cli {
#[arg(long, global = true)]
pub json: bool,
#[arg(long, global = true)]
pub quiet: bool,
#[command(subcommand)]
pub command: Command,
}
#[derive(Subcommand, Debug)]
pub enum Command {
Stats,
Entity(commands::entity::Args),
Relations(commands::relations::Args),
Search(commands::search::Args),
List(commands::list::Args),
Context(commands::context::Args),
Overview(commands::overview::Args),
Type(commands::type_cmd::Args),
Health(commands::health::Args),
Export(commands::export::Args),
Init(commands::init::InitArgs),
Quickstart(commands::quickstart::Args),
#[cfg(feature = "mem-repo")]
Install(commands::install::Args),
Link(commands::link::LinkArgs),
Publish(commands::publish::Args),
Unpublish(commands::unpublish::Args),
Domain {
#[command(subcommand)]
action: commands::domain::DomainAction,
},
Admin {
#[command(subcommand)]
action: commands::admin::AdminAction,
},
Login(commands::login::Args),
Logout(commands::logout::Args),
Create(commands::create::Args),
Update(commands::update::Args),
Relate(commands::relate::Args),
Delete(commands::delete::Args),
Rename(commands::rename::Args),
#[cfg(feature = "mem-repo")]
#[command(name = "batch-update")]
BatchUpdate(commands::batch_update::Args),
#[cfg(feature = "mem-repo")]
Recover(commands::recover::Args),
Changes(commands::changes::Args),
Reload(commands::reload::Args),
#[cfg(feature = "mem-repo")]
Fetch(commands::transport::FetchArgs),
#[cfg(feature = "mem-repo")]
Pull(commands::transport::PullArgs),
#[cfg(feature = "mem-repo")]
Push(commands::transport::PushArgs),
#[cfg(feature = "mem-repo")]
#[command(name = "branch-reset")]
BranchReset(commands::branch_reset::BranchResetArgs),
#[cfg(feature = "mem-repo")]
Mem {
#[command(subcommand)]
action: commands::mem::MemAction,
},
#[cfg(feature = "mem-repo")]
#[command(name = "mem-repo")]
MemRepo {
#[command(subcommand)]
action: commands::mem_repo::MemRepoAction,
},
#[cfg(feature = "mem-repo")]
Workspace {
#[command(subcommand)]
action: commands::workspace::WorkspaceAction,
},
Schema(commands::schema::Args),
Pipeline(commands::pipeline::Args),
}