diff --git a/nomos-cli/src/cmds/chat/mod.rs b/nomos-cli/src/cmds/chat/mod.rs index d9a114d3..5242c191 100644 --- a/nomos-cli/src/cmds/chat/mod.rs +++ b/nomos-cli/src/cmds/chat/mod.rs @@ -63,6 +63,12 @@ pub struct NomosChat { /// The node to connect to to fetch blocks and blobs #[clap(long)] pub node: Url, + /// Author for non interactive message formation + #[clap(long, requires("message"))] + pub author: Option, + /// Message for non interactive message formation + #[clap(long, requires("author"))] + pub message: Option, } pub struct App { @@ -86,12 +92,6 @@ impl NomosChat { as ServiceData>::Settings, >(std::fs::File::open(&self.network_config)?)?; let da_protocol = self.da_protocol.clone(); - // setup terminal - enable_raw_mode()?; - let mut stdout = io::stdout(); - execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?; - let backend = CrosstermBackend::new(stdout); - let mut terminal = Terminal::new(backend)?; let node_addr = Some(self.node.clone()); @@ -125,6 +125,21 @@ impl NomosChat { .wait_finished() }); + if let Some(author) = self.author.as_ref() { + let message = self + .message + .as_ref() + .expect("Should be available if author is set"); + return run_once(author, message, payload_sender); + } + + // setup terminal + enable_raw_mode()?; + let mut stdout = io::stdout(); + execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?; + let backend = CrosstermBackend::new(stdout); + let mut terminal = Terminal::new(backend)?; + let app = App { input: Input::default(), username: None, @@ -154,6 +169,24 @@ impl NomosChat { } } +fn run_once( + author: &str, + message: &str, + payload_sender: UnboundedSender>, +) -> Result<(), Box> { + payload_sender.send( + wire::serialize(&ChatMessage { + author: author.to_string(), + message: message.to_string(), + _nonce: rand::random(), + }) + .unwrap() + .into(), + )?; + + Ok(()) +} + fn run_app(terminal: &mut Terminal, mut app: App) { let (message_tx, message_rx) = std::sync::mpsc::channel(); let node = app.node.clone(); diff --git a/nomos-cli/src/cmds/disseminate/mod.rs b/nomos-cli/src/cmds/disseminate/mod.rs index 8e560fee..fe8ebc6d 100644 --- a/nomos-cli/src/cmds/disseminate/mod.rs +++ b/nomos-cli/src/cmds/disseminate/mod.rs @@ -12,7 +12,7 @@ use tokio::sync::Mutex; #[derive(Args, Debug, Default)] pub struct Disseminate { // TODO: accept bytes - #[clap(short, long)] + #[clap(short, long, required_unless_present("file"))] pub data: Option, /// Path to the network config file #[clap(short, long)] @@ -44,15 +44,15 @@ impl Disseminate { as ServiceData>::Settings, >(std::fs::File::open(&self.network_config)?)?; let (status_updates, rx) = std::sync::mpsc::channel(); - let bytes: Box<[u8]> = match (&self.data, &self.file) { - (Some(data), None) => data.clone().as_bytes().into(), - (None, Some(file_path)) => { - let file_bytes = std::fs::read(file_path)?; - file_bytes.into_boxed_slice() - } - (Some(_), Some(_)) => return Err("Cannot specify both data and file".into()), - (None, None) => return Err("Either data or file must be specified".into()), + + let bytes: Box<[u8]> = if let Some(data) = &self.data { + data.clone().as_bytes().into() + } else { + let file_path = self.file.as_ref().unwrap(); + let file_bytes = std::fs::read(file_path)?; + file_bytes.into_boxed_slice() }; + let timeout = Duration::from_secs(self.timeout); let da_protocol = self.da_protocol.clone(); let node_addr = self.node_addr.clone();