Add more output options to query-lib
This commit is contained in:
parent
c493a92246
commit
411149023c
5 changed files with 32 additions and 4 deletions
12
src/cli.rs
12
src/cli.rs
|
@ -19,7 +19,7 @@ struct Cli {
|
|||
pub enum Commands {
|
||||
Info,
|
||||
Channels(ChannelsArgs),
|
||||
Clients,
|
||||
Clients(ClientsArgs),
|
||||
Fetch(FetchArgs),
|
||||
Message(MessageArgs),
|
||||
Move(MoveArgs),
|
||||
|
@ -31,6 +31,16 @@ pub enum Commands {
|
|||
pub struct ChannelsArgs {
|
||||
#[arg(long)]
|
||||
pub spacers: bool,
|
||||
#[arg(long)]
|
||||
pub only_empty: bool,
|
||||
#[arg(long)]
|
||||
pub only_filled: bool,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
pub struct ClientsArgs {
|
||||
#[arg(long)]
|
||||
pub uid: bool,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
|
|
|
@ -88,7 +88,7 @@ pub fn channellist(connection: &mut Telnet) -> Result<Response, String> {
|
|||
}
|
||||
|
||||
pub fn clientlist(connection: &mut Telnet) -> Result<Response, String> {
|
||||
send_command(connection, "clientlist", true)
|
||||
send_command(connection, "clientlist -uid", true)
|
||||
}
|
||||
|
||||
pub fn whoami(connection: &mut Telnet) -> Result<Response, String> {
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -71,6 +71,12 @@ fn main() -> Result<(), Error> {
|
|||
match wrappers::get_channels(&mut connection, args.spacers) {
|
||||
Ok(channels) => {
|
||||
for channel in channels {
|
||||
if args.only_empty && channel.total_clients > 0 {
|
||||
continue; // Skip non-empty channels
|
||||
}
|
||||
if args.only_filled && channel.total_clients == 0 {
|
||||
continue; // Skip empty channels
|
||||
}
|
||||
println!("{}", channel.channel_name);
|
||||
}
|
||||
}
|
||||
|
@ -80,11 +86,16 @@ fn main() -> Result<(), Error> {
|
|||
}
|
||||
}
|
||||
|
||||
Commands::Clients => {
|
||||
Commands::Clients(args) => {
|
||||
match wrappers::get_clients(&mut connection) {
|
||||
Ok(clients) => {
|
||||
for client in clients {
|
||||
println!("{}", client.client_nickname);
|
||||
if args.uid {
|
||||
println!("{} {}", client.uid, client.client_nickname);
|
||||
}
|
||||
else {
|
||||
println!("{}", client.client_nickname);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(msg) => {
|
||||
|
|
|
@ -11,6 +11,7 @@ pub struct Channel {
|
|||
pub channel_name: String,
|
||||
pub channel_topic: String,
|
||||
pub channel_flag_are_subscribed: bool,
|
||||
pub total_clients: i32
|
||||
}
|
||||
|
||||
impl Display for Channel {
|
||||
|
@ -38,6 +39,9 @@ impl From<ParameterList> for Channel {
|
|||
channel_flag_are_subscribed: parameter_find(&value, "channel_flag_are_subscribed")
|
||||
.unwrap_or_default()
|
||||
.parse::<i32>().unwrap_or(0) == 1,
|
||||
total_clients: parameter_find(&value, "total_clients")
|
||||
.unwrap_or_default()
|
||||
.parse::<i32>().unwrap_or(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ pub struct Client {
|
|||
pub client_database_id: i32,
|
||||
pub client_nickname: String,
|
||||
pub client_type: i32,
|
||||
pub uid: String,
|
||||
}
|
||||
|
||||
impl Display for Client {
|
||||
|
@ -35,6 +36,8 @@ impl From<ParameterList> for Client {
|
|||
client_type: parameter_find(&value, "channel_topic")
|
||||
.unwrap_or_default()
|
||||
.parse::<i32>().unwrap_or(0),
|
||||
uid: parameter_find(&value, "client_unique_identifier")
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue