aboutsummaryrefslogtreecommitdiffstats
path: root/adenosine-cli/src/bin/adenosine.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-10-27 23:03:28 -0700
committerBryan Newbold <bnewbold@robocracy.org>2022-10-27 23:03:28 -0700
commit7ba5eec5a87c14f8cfe944131d6fb7229648d81f (patch)
treef6def4f470ddd8242f7aa37f1c485a9b588b9038 /adenosine-cli/src/bin/adenosine.rs
parentdc24074377875b7f500b20e4f6088930f2eef4ea (diff)
downloadadenosine-7ba5eec5a87c14f8cfe944131d6fb7229648d81f.tar.gz
adenosine-7ba5eec5a87c14f8cfe944131d6fb7229648d81f.zip
cli: parse fields as body or query params from args
Diffstat (limited to 'adenosine-cli/src/bin/adenosine.rs')
-rw-r--r--adenosine-cli/src/bin/adenosine.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/adenosine-cli/src/bin/adenosine.rs b/adenosine-cli/src/bin/adenosine.rs
index 1d23c27..33f74c9 100644
--- a/adenosine-cli/src/bin/adenosine.rs
+++ b/adenosine-cli/src/bin/adenosine.rs
@@ -123,11 +123,11 @@ enum Command {
Create {
collection: String,
- fields: String,
+ fields: Vec<ArgField>,
},
Update {
uri: AtUri,
- fields: String,
+ fields: Vec<ArgField>,
},
Delete {
uri: AtUri,
@@ -144,7 +144,7 @@ enum Command {
Xrpc {
method: XrpcMethod,
nsid: String,
- fields: Option<String>,
+ fields: Vec<ArgField>,
},
/// Sub-commands for managing account
@@ -274,7 +274,7 @@ fn run(opt: Opt) -> Result<()> {
if let Some(c) = cid {
params.insert("cid".to_string(), c);
}
- xrpc_client.post("com.atproto.repoGetRecord", Some(params), json!({}))?
+ xrpc_client.get("com.atproto.repoGetRecord", Some(params))?
}
Command::Ls { uri } => {
// TODO: option to print fully-qualified path?
@@ -303,7 +303,9 @@ fn run(opt: Opt) -> Result<()> {
}
Command::Create { collection, fields } => {
params.insert("collection".to_string(), collection);
- unimplemented!()
+ update_params_from_fields(&fields, &mut params);
+ let val = value_from_fields(fields);
+ xrpc_client.post("com.atproto.repoCreateRecord", Some(params), val)?
}
Command::Update { uri, fields } => {
params.insert("did".to_string(), uri.repository.to_string());
@@ -315,7 +317,13 @@ fn run(opt: Opt) -> Result<()> {
"rkey".to_string(),
uri.record.ok_or(anyhow!("record key required"))?,
);
- unimplemented!()
+ // fetch existing, extend map with fields, put the updated value
+ let mut record = xrpc_client
+ .get("com.atproto.repoGetRecord", Some(params.clone()))?
+ .unwrap_or(json!({}));
+ update_params_from_fields(&fields, &mut params);
+ update_value_from_fields(fields, &mut record);
+ xrpc_client.post("com.atproto.repoPutRecord", Some(params), record)?
}
Command::Delete { uri } => {
params.insert("did".to_string(), uri.repository.to_string());
@@ -334,11 +342,11 @@ fn run(opt: Opt) -> Result<()> {
nsid,
fields,
} => {
- let body: Value = ().into();
+ update_params_from_fields(&fields, &mut params);
+ let body = value_from_fields(fields);
match method {
- // XXX: parse params
- XrpcMethod::Get => xrpc_client.get(&nsid, None)?,
- XrpcMethod::Post => xrpc_client.post(&nsid, None, body)?,
+ XrpcMethod::Get => xrpc_client.get(&nsid, Some(params))?,
+ XrpcMethod::Post => xrpc_client.post(&nsid, Some(params), body)?,
}
}
Command::Account {