Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion crates/buzz-cli/src/commands/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ pub async fn dispatch(
about,
nip05,
} => {
// `--about -` matches messages/notes: substitute stdin for the
// sentinel. Without this, clap stores the literal "-" and the
// published kind:0 about field collapses to a single dash.
let about = resolve_about_arg(about, || crate::validate::read_or_stdin("-"))?;
cmd_set_profile(
client,
name.as_deref(),
Expand All @@ -571,15 +575,55 @@ pub async fn dispatch(
}
}

/// Resolve `--about`, treating `-` as "read stdin" the way messages/notes do.
fn resolve_about_arg(
about: Option<String>,
read_stdin: impl FnOnce() -> Result<String, CliError>,
) -> Result<Option<String>, CliError> {
match about.as_deref() {
Some("-") => Ok(Some(read_stdin()?)),
Some(value) => Ok(Some(value.to_string())),
None => Ok(None),
}
}

#[cfg(test)]
mod tests {
use super::{
owned_agent_pubkeys_from_events, owner_scoped_profiles, owner_verification,
presence_subject,
presence_subject, resolve_about_arg,
};
use crate::error::CliError;
use nostr::Keys;
use serde_json::json;

#[test]
fn resolve_about_arg_passes_through_literal_bios() {
assert_eq!(
resolve_about_arg(Some("Scout Bee".into()), || unreachable!()).unwrap(),
Some("Scout Bee".into())
);
assert_eq!(resolve_about_arg(None, || unreachable!()).unwrap(), None);
}

#[test]
fn resolve_about_arg_reads_stdin_for_dash_sentinel() {
let about = resolve_about_arg(Some("-".into()), || {
Ok("line one\nline two\n".into())
})
.unwrap();
assert_eq!(about.as_deref(), Some("line one\nline two\n"));
}

#[test]
fn resolve_about_arg_propagates_stdin_errors() {
let err = resolve_about_arg(Some("-".into()), || {
Err(CliError::Other("failed to read stdin".into()))
})
.unwrap_err();
assert!(matches!(err, CliError::Other(_)));
}

#[test]
fn owned_agent_lookup_matches_exact_name_case_insensitively() {
let events = vec![
Expand Down
2 changes: 1 addition & 1 deletion crates/buzz-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ pub enum UsersCmd {
/// Avatar URL
#[arg(long)]
avatar: Option<String>,
/// Bio / about text
/// Bio / about text. Use '-' to read from stdin
#[arg(long)]
about: Option<String>,
/// NIP-05 identifier (e.g. user@example.com)
Expand Down