Skip to content

Commit 53af6f7

Browse files
committed
feat: add script-friendly password output
Support --print-password-only for user add and use it in AWS bootstrap scripts to capture generated passwords reliably.
1 parent 7f52253 commit 53af6f7

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

infra/aws/cloud-init/opencode-cloud-quick.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ write_files:
111111
log "opencode-cloud setup: bootstrap complete"
112112
113113
log "opencode-cloud setup: create user ${OPENCODE_USERNAME}"
114-
user_output="$(opencode-cloud user add "${OPENCODE_USERNAME}" --generate)"
115-
OPENCODE_PASSWORD="$(printf '%s\n' "$user_output" | sed -n 's/.*Password: //p' | tail -n 1)"
114+
OPENCODE_PASSWORD="$(opencode-cloud user add "${OPENCODE_USERNAME}" --generate --print-password-only)"
116115
if [ -z "$OPENCODE_PASSWORD" ]; then
117116
log "opencode-cloud setup: failed to read generated password"
118117
exit 1

infra/aws/cloudformation/opencode-cloud-quick.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,7 @@ Resources:
680680
fi
681681
682682
log "opencode-cloud setup: create user $OPENCODE_USERNAME"
683-
user_output="$(opencode-cloud user add "$OPENCODE_USERNAME" --generate)"
684-
OPENCODE_PASSWORD="$(printf '%s\n' "$user_output" | sed -n 's/.*Password: //p' | tail -n 1)"
683+
OPENCODE_PASSWORD="$(opencode-cloud user add "$OPENCODE_USERNAME" --generate --print-password-only)"
685684
if [ -z "$OPENCODE_PASSWORD" ]; then
686685
log "opencode-cloud setup: failed to read generated password"
687686
signal_result 1 "opencode-cloud failed to read generated password"

packages/cli-rust/src/commands/user/add.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ pub struct UserAddArgs {
2222
/// Generate a random secure password instead of prompting
2323
#[arg(long, short)]
2424
pub generate: bool,
25+
26+
/// Print only the generated password for scripting
27+
#[arg(long)]
28+
pub print_password_only: bool,
2529
}
2630

2731
/// Generate a secure random password
@@ -60,6 +64,10 @@ pub async fn cmd_user_add(
6064
quiet: bool,
6165
_verbose: u8,
6266
) -> Result<()> {
67+
if args.print_password_only && !args.generate {
68+
bail!("--print-password-only requires --generate");
69+
}
70+
6371
// Get username - prompt if not provided
6472
let username = if let Some(ref name) = args.username {
6573
validate_username(name).map_err(|e| anyhow::anyhow!("{e}"))?;
@@ -124,6 +132,11 @@ pub async fn cmd_user_add(
124132
save_config(&config)?;
125133
}
126134

135+
if args.print_password_only {
136+
println!("{password}");
137+
return Ok(());
138+
}
139+
127140
// Display success
128141
if !quiet {
129142
println!(

0 commit comments

Comments
 (0)