feat: add options to set authfile and history size

This commit is contained in:
Himadri Bhattacharjee
2025-04-17 11:49:48 +05:30
parent 640041e937
commit 8b4d58ce2f
4 changed files with 67 additions and 7 deletions

41
Cargo.lock generated
View File

@@ -335,6 +335,46 @@ dependencies = [
"inout",
]
[[package]]
name = "clap"
version = "4.5.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2df961d8c8a0d08aa9945718ccf584145eee3f3aa06cddbeac12933781102e04"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "132dbda40fb6753878316a489d5a1242a8ef2f0d9e47ba01c951ea8aa7d013a5"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "colorchoice"
version = "1.0.3"
@@ -1462,6 +1502,7 @@ name = "publik"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"env_logger",
"log",
"ratatui",

View File

@@ -5,6 +5,7 @@ edition = "2024"
[dependencies]
anyhow = "1.0.97"
clap = { version = "4.5.36", features = ["derive"] }
env_logger = "0.11.7"
log = "0.4.26"
ratatui = "0.29.0"

View File

@@ -15,7 +15,7 @@ interface or by editing it externally.
- [ ] `/commit` command to commit in-memory changes to Authfile
- [ ] `/rename` command
- [ ] `#mention` tags
- [ ] Adjustable parameters like history size and Authfile paths
- [x] Adjustable parameters like history size and Authfile paths
### Authfile

View File

@@ -2,7 +2,8 @@ use std::collections::{HashMap, HashSet};
use std::path::Path;
use std::sync::Arc;
use authfile::Entity;
use anyhow::Result;
use clap::Parser;
use ratatui::backend::TermionBackend;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Style};
@@ -17,7 +18,9 @@ use russh::{Channel, ChannelId, Pty};
use tokio::sync::RwLock;
use tokio::sync::mpsc::{UnboundedSender, unbounded_channel};
use tui_textarea::TextArea;
mod authfile;
use authfile::Entity;
type SshTerminal = Terminal<TermionBackend<TerminalHandle>>;
@@ -490,13 +493,27 @@ impl Drop for AppServer {
}
}
#[derive(Parser, Debug)]
#[command(version, about)]
struct Args {
/// The number of messages to store in chat history before the first disappears
#[arg(long, default_value = "128")]
history_size: usize,
/// Path to the Authfile or the SSH authorized_keys file
#[arg(long, short, default_value = "./Authfile")]
authfile: String,
}
#[tokio::main]
async fn main() {
async fn main() -> Result<()> {
env_logger::builder()
.filter_level(log::LevelFilter::Warn)
.filter_level(log::LevelFilter::Debug)
.init();
let keychain = authfile::read(Path::new("./authfile")).await.unwrap();
let args = Args::parse();
let keychain = authfile::read(Path::new(&args.authfile)).await?;
let key_data_pool = new_atomic(keychain.key_pool);
let key_data_to_id = new_atomic(HashMap::new());
let id_to_user = new_atomic(HashMap::new());
@@ -511,7 +528,7 @@ async fn main() {
let keychain = new_atomic(keychain.entities);
let app = App {
history: AllocRingBuffer::new(128),
history: AllocRingBuffer::new(args.history_size),
};
let app = new_atomic(app);
@@ -526,5 +543,6 @@ async fn main() {
clients,
id: 0,
};
sh.run().await.unwrap();
sh.run().await?;
Ok(())
}