Skip to content

Commit e53e266

Browse files
committed
fixup! CLI tool to issue user registration tokens
1 parent 7c680dd commit e53e266

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

crates/cli/src/commands/manage.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,15 @@ enum Subcommand {
107107
token: Option<String>,
108108

109109
/// Maximum number of times this token can be used.
110-
/// If not provided, the token can be used an unlimited number of times.
111-
#[arg(long)]
110+
/// If not provided, the token can be used only once, unless the
111+
/// `--unlimited` flag is set.
112+
#[arg(long, group = "token-usage-limit")]
112113
usage_limit: Option<u32>,
113114

115+
/// Allow the token to be used an unlimited number of times.
116+
#[arg(long, action = ArgAction::SetTrue, group = "token-usage-limit")]
117+
unlimited: bool,
118+
114119
/// Time in seconds after which the token expires.
115120
/// If not provided, the token never expires.
116121
#[arg(long)]
@@ -355,10 +360,18 @@ impl Options {
355360
SC::IssueUserRegistrationToken {
356361
token,
357362
usage_limit,
363+
unlimited,
358364
expires_in,
359365
} => {
360366
let _span = info_span!("cli.manage.add_user_registration_token").entered();
361367

368+
let usage_limit = match (usage_limit, unlimited) {
369+
(Some(usage_limit), false) => Some(usage_limit),
370+
(None, false) => Some(1),
371+
(None, true) => None,
372+
(Some(_), true) => unreachable!(), // This should be handled by the clap group
373+
};
374+
362375
let database_config = DatabaseConfig::extract_or_default(figment)?;
363376
let mut conn = database_connection_from_config(&database_config).await?;
364377
let txn = conn.begin().await?;

0 commit comments

Comments
 (0)