Skip to content

Commit

Permalink
chore: make ugi a separate command
Browse files Browse the repository at this point in the history
  • Loading branch information
raklaptudirm committed May 28, 2024
1 parent 0a3017f commit ceb5d2c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
4 changes: 3 additions & 1 deletion uxi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<T: Send> Client<T> {
commands: HashMap::from([
("quit".to_owned(), inbuilt::commands::quit()),
("isready".to_owned(), inbuilt::commands::isready()),
("ugi".to_owned(), inbuilt::commands::uxi()),
("ugi".to_owned(), inbuilt::commands::ugi()),
("setoption".to_owned(), inbuilt::commands::setoption()),
("options".to_owned(), inbuilt::commands::options()),
]),
Expand Down Expand Up @@ -174,6 +174,8 @@ impl<T: Send> Client<T> {
}

pub fn protocol(mut self, name: &str) -> Self {
assert!(!self.commands.contains_key(name));

// Move the previous protocol identifier command to the new name.
self.commands.remove(&self.initial_context.protocol);
self.commands
Expand Down
2 changes: 1 addition & 1 deletion uxi/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Context {
impl Default for Context {
fn default() -> Self {
Context {
protocol: "ugi".to_string(),
protocol: "".to_string(),
engine: "Nameless v0.0.0".to_string(),
author: "Anonymous".to_string(),
options: HashMap::new(),
Expand Down
37 changes: 26 additions & 11 deletions uxi/src/inbuilt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<T: Send> DerefMut for BundledCtx<T> {
}

pub mod commands {
use crate::{error, quit, Command, Flag, Parameter, RunError};
use crate::{context::Context, error, quit, Command, Flag, Parameter, RunError};

pub fn quit<C: Send>() -> Command<C> {
Command::new(|_ctx| quit!())
Expand All @@ -73,22 +73,37 @@ pub mod commands {
Command::new(|ctx| {
let ctx = ctx.lock();

println!("id name {}", ctx.client.engine);
println!("id author {}", ctx.client.author);
println!();
if !ctx.client.options.is_empty() {
for (name, option) in ctx.client.options.clone() {
println!("option name {} type {}", name, option);
}

println!();
}
print_protocol_info(&ctx.client);
println!("{}ok", ctx.client.protocol);

Ok(())
})
}

pub fn ugi<C: Send>() -> Command<C> {
Command::new(|ctx| {
let ctx = ctx.lock();

print_protocol_info(&ctx.client);
println!("ugiok");

Ok(())
})
}

fn print_protocol_info(ctx: &Context) {
println!("id name {}", ctx.engine);
println!("id author {}", ctx.author);
println!();
if !ctx.options.is_empty() {
for (name, option) in ctx.options.clone() {
println!("option name {} type {}", name, option);
}

println!();
}
}

pub fn setoption<C: Send>() -> Command<C> {
Command::new(|ctx| {
let name = ctx.get_single_flag("name");
Expand Down

0 comments on commit ceb5d2c

Please sign in to comment.