-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nomos chat app non interactive #567
Conversation
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() | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous solution, even being readable and concise, the panic message differed from the user friendly warning that Clap produced. The output when user provides the --author
flag, but forgets the --message
now is:
error: the following required arguments were not provided:
--message <MESSAGE>
Usage: nomos-cli chat --network-config <NETWORK_CONFIG> --node <NODE> --message <MESSAGE> --author <AUTHOR>
If user doesn't provide the author nor message, the app goes into the interactive mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Bincode has no external cli tool to encode independantly, so either we need to write that tool, that we would be able to use from scripts, or we use chatapp to do encoding to ChatMessage directly, because it's specific to it.
in my opinion, it's good enough to do encoding in the chatapp, as you implemented.
* Add option to send chat message non iteractively via nomos cli * Use clap to check if data or file is set * Require author if message flag set
Add params to nomos cli app to send chat message and exit the application. This will be used alongside the dissemination app to produce constant traffic in the testnet.
For chat app to decode messages, they need to be in ChatMessage struct, encoded with bincode. Bincode has no external cli tool to encode independantly, so either we need to write that tool, that we would be able to use from scripts, or we use chatapp to do encoding to ChatMessage directly, because it's specific to it.
Dissemination app will still be used for big data blob uploads to the testnet.