add --include-private to db dump rpc

This commit is contained in:
Aiden McClelland
2024-03-11 17:15:18 -06:00
parent 64fb002168
commit 750f35bc36
2 changed files with 27 additions and 9 deletions

View File

@@ -182,8 +182,18 @@ pub enum RevisionsRes {
Dump(Dump), Dump(Dump),
} }
#[derive(Deserialize, Serialize, Parser)]
#[serde(rename_all = "kebab-case")]
#[command(rename_all = "kebab-case")]
pub struct CliDumpParams {
path: Option<PathBuf>,
}
#[instrument(skip_all)] #[instrument(skip_all)]
async fn cli_dump(ctx: CliContext, DumpParams { path }: DumpParams) -> Result<Dump, RpcError> { async fn cli_dump(
ctx: CliContext,
CliDumpParams { path }: CliDumpParams,
) -> Result<Dump, RpcError> {
let dump = if let Some(path) = path { let dump = if let Some(path) = path {
PatchDb::open(path).await?.dump(&ROOT).await PatchDb::open(path).await?.dump(&ROOT).await
} else { } else {
@@ -197,15 +207,23 @@ async fn cli_dump(ctx: CliContext, DumpParams { path }: DumpParams) -> Result<Du
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
#[command(rename_all = "kebab-case")] #[command(rename_all = "kebab-case")]
pub struct DumpParams { pub struct DumpParams {
path: Option<PathBuf>, #[arg(long = "include-private", short = 'p')]
#[serde(default)]
include_private: bool,
} }
// #[command( pub async fn dump(
// custom_cli(cli_dump(async, context(CliContext))), ctx: RpcContext,
// display(display_serializable) DumpParams { include_private }: DumpParams,
// )] ) -> Result<Dump, Error> {
pub async fn dump(ctx: RpcContext, _: DumpParams) -> Result<Dump, Error> { Ok(ctx
Ok(ctx.db.dump(&*PUBLIC).await) .db
.dump(&if include_private {
ROOT
} else {
PUBLIC.borrowed()
})
.await)
} }
#[instrument(skip_all)] #[instrument(skip_all)]