Skip to content
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

Merged
merged 3 commits into from
Jan 29, 2024
Merged

Nomos chat app non interactive #567

merged 3 commits into from
Jan 29, 2024

Conversation

bacv
Copy link
Member

@bacv bacv commented Jan 26, 2024

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.

@bacv bacv added the testnet label Jan 26, 2024
@bacv bacv added this to the Nomos testnet (playground) milestone Jan 26, 2024
@bacv bacv self-assigned this Jan 26, 2024
Comment on lines -47 to +55
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()
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why this change?

Copy link
Member Author

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

Copy link
Contributor

@youngjoon-lee youngjoon-lee left a 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.

@bacv bacv merged commit f33c261 into master Jan 29, 2024
7 checks passed
@bacv bacv deleted the demo-app-non-interactive branch January 29, 2024 07:43
al8n pushed a commit that referenced this pull request Mar 4, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants