feat: add REST HTTP server mode with OpenAPI documentation and Swagger UI

Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-10 21:27:13 -03:00
parent 741d0f19cc
commit 64789ef48b
5 changed files with 688 additions and 1 deletions

View File

@@ -80,9 +80,13 @@ struct ModeArgs {
))]
info: bool,
#[arg(group("mode"), help_heading("Mode Options"), short('S'), long, conflicts_with_all(["save", "get", "diff", "list", "update", "delete", "info"]))]
#[arg(group("mode"), help_heading("Mode Options"), short('S'), long, conflicts_with_all(["save", "get", "diff", "list", "update", "delete", "info", "server"]))]
#[arg(help("Show status of directories and supported compression algorithms"))]
status: bool,
#[arg(group("mode"), help_heading("Mode Options"), long, conflicts_with_all(["save", "get", "diff", "list", "update", "delete", "info", "status"]))]
#[arg(help("Start REST HTTP server on specified address:port or socket path"))]
server: Option<String>,
}
/**
@@ -142,6 +146,10 @@ struct OptionsArgs {
#[arg(long, value_enum, default_value("table"))]
#[arg(help("Output format (only works with --info, --status, --list)"))]
output_format: Option<String>,
#[arg(long, env("KEEP_SERVER_PASSWORD"))]
#[arg(help("Password for server authentication (requires --server)"))]
server_password: Option<String>,
}
/**
@@ -158,6 +166,7 @@ enum KeepModes {
Delete,
Info,
Status,
Server,
}
/**
@@ -251,6 +260,8 @@ fn main() -> Result<(), Error> {
mode = KeepModes::Info;
} else if args.mode.status {
mode = KeepModes::Status;
} else if args.mode.server.is_some() {
mode = KeepModes::Server;
}
if mode == KeepModes::Unknown {
@@ -279,6 +290,14 @@ fn main() -> Result<(), Error> {
).exit();
}
// Validate server password usage
if args.options.server_password.is_some() && mode != KeepModes::Server {
cmd.error(
ErrorKind::InvalidValue,
"--server-password can only be used with --server mode"
).exit();
}
debug!("MAIN: args: {:?}", args);
debug!("MAIN: ids: {:?}", ids);
debug!("MAIN: tags: {:?}", tags);
@@ -333,6 +352,9 @@ fn main() -> Result<(), Error> {
KeepModes::Status => {
crate::modes::status::mode_status(&mut cmd, &args, data_path, db_path)?
}
KeepModes::Server => {
crate::modes::server::mode_server(&mut cmd, &args, &mut conn, data_path)?
}
_ => todo!(),
}