Merge branch 'fix-admin-help' into 'next'
fix `@conduit help` not working in the admin room See merge request famedly/conduit!392
This commit is contained in:
commit
c948324cf2
3 changed files with 41 additions and 9 deletions
|
@ -83,7 +83,7 @@ thread_local = "1.1.3"
|
|||
hmac = "0.12.1"
|
||||
sha-1 = "0.10.0"
|
||||
# used for conduit's CLI and admin room command parsing
|
||||
clap = { version = "4.0.11", default-features = false, features = ["std", "derive"] }
|
||||
clap = { version = "4.0.11", default-features = false, features = ["std", "derive", "help", "usage", "error-context"] }
|
||||
futures-util = { version = "0.3.17", default-features = false }
|
||||
# Used for reading the configuration from conduit.toml & environment variables
|
||||
figment = { version = "0.10.6", features = ["env", "toml"] }
|
||||
|
|
|
@ -65,7 +65,7 @@ use tracing::{error, info, warn};
|
|||
///
|
||||
/// # Examples:
|
||||
/// ```rust
|
||||
/// # use conduit::server_server::FedDest;
|
||||
/// # use conduit::api::server_server::FedDest;
|
||||
/// # fn main() -> Result<(), std::net::AddrParseError> {
|
||||
/// FedDest::Literal("198.51.100.3:8448".parse()?);
|
||||
/// FedDest::Literal("[2001:db8::4:5]:443".parse()?);
|
||||
|
|
|
@ -37,10 +37,11 @@ use crate::{
|
|||
|
||||
use super::pdu::PduBuilder;
|
||||
|
||||
#[cfg_attr(test, derive(Debug))]
|
||||
#[derive(Parser)]
|
||||
#[clap(name = "@conduit:server.name:", version = env!("CARGO_PKG_VERSION"))]
|
||||
#[command(name = "@conduit:server.name:", version = env!("CARGO_PKG_VERSION"))]
|
||||
enum AdminCommand {
|
||||
#[clap(verbatim_doc_comment)]
|
||||
#[command(verbatim_doc_comment)]
|
||||
/// Register an appservice using its registration YAML
|
||||
///
|
||||
/// This command needs a YAML generated by an appservice (such as a bridge),
|
||||
|
@ -80,12 +81,12 @@ enum AdminCommand {
|
|||
/// User will not be removed from all rooms by default.
|
||||
/// Use --leave-rooms to force the user to leave all rooms
|
||||
DeactivateUser {
|
||||
#[clap(short, long)]
|
||||
#[arg(short, long)]
|
||||
leave_rooms: bool,
|
||||
user_id: Box<UserId>,
|
||||
},
|
||||
|
||||
#[clap(verbatim_doc_comment)]
|
||||
#[command(verbatim_doc_comment)]
|
||||
/// Deactivate a list of users
|
||||
///
|
||||
/// Recommended to use in conjunction with list-local-users.
|
||||
|
@ -100,10 +101,10 @@ enum AdminCommand {
|
|||
/// # User list here
|
||||
/// # ```
|
||||
DeactivateAll {
|
||||
#[clap(short, long)]
|
||||
#[arg(short, long)]
|
||||
/// Remove users from their joined rooms
|
||||
leave_rooms: bool,
|
||||
#[clap(short, long)]
|
||||
#[arg(short, long)]
|
||||
/// Also deactivate admin accounts
|
||||
force: bool,
|
||||
},
|
||||
|
@ -114,7 +115,7 @@ enum AdminCommand {
|
|||
event_id: Box<EventId>,
|
||||
},
|
||||
|
||||
#[clap(verbatim_doc_comment)]
|
||||
#[command(verbatim_doc_comment)]
|
||||
/// Parse and print a PDU from a JSON
|
||||
///
|
||||
/// The PDU event is only checked for validity and is not added to the
|
||||
|
@ -1160,3 +1161,34 @@ impl Service {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn get_help_short() {
|
||||
get_help_inner("-h");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_help_long() {
|
||||
get_help_inner("--help");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_help_subcommand() {
|
||||
get_help_inner("help");
|
||||
}
|
||||
|
||||
fn get_help_inner(input: &str) {
|
||||
let error = AdminCommand::try_parse_from(["argv[0] doesn't matter", input])
|
||||
.unwrap_err()
|
||||
.to_string();
|
||||
|
||||
// Search for a handful of keywords that suggest the help printed properly
|
||||
assert!(error.contains("Usage:"));
|
||||
assert!(error.contains("Commands:"));
|
||||
assert!(error.contains("Options:"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue