Skip to content

Commit

Permalink
feat(example-sync): add ticket command
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Jul 13, 2023
1 parent 49ea27c commit c4b38e1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions iroh/examples/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async fn run(args: Args) -> anyhow::Result<()> {
_ = tokio::signal::ctrl_c() => {
println!("> aborted");
}
res = handle_command(cmd, &doc, &log_filter) => if let Err(err) = res {
res = handle_command(cmd, &doc, &our_ticket, &log_filter) => if let Err(err) = res {
println!("> error: {err}");
},
};
Expand All @@ -243,7 +243,7 @@ async fn run(args: Args) -> anyhow::Result<()> {
Ok(())
}

async fn handle_command(cmd: Cmd, doc: &Doc, log_filter: &LogLevelReload) -> anyhow::Result<()> {
async fn handle_command(cmd: Cmd, doc: &Doc, ticket: &Ticket, log_filter: &LogLevelReload) -> anyhow::Result<()> {
match cmd {
Cmd::Set { key, value } => {
doc.insert_bytes(&key, value.into_bytes().into()).await?;
Expand All @@ -267,6 +267,9 @@ async fn handle_command(cmd: Cmd, doc: &Doc, log_filter: &LogLevelReload) -> any
println!("{}", fmt_entry(&entry),);
}
}
Cmd::Ticket => {
println!("Ticket: {ticket}");
}
Cmd::Log { directive } => {
let next_filter = EnvFilter::from_str(&directive)?;
log_filter.modify(|layer| *layer = next_filter)?;
Expand Down Expand Up @@ -300,6 +303,8 @@ pub enum Cmd {
/// Optionally list only entries whose key starts with PREFIX.
prefix: Option<String>,
},
/// Print the ticket with which other peers can join our document.
Ticket,
/// Change the log level
Log {
/// The log level or log filtering directive
Expand Down Expand Up @@ -449,7 +454,6 @@ fn init_logging() -> LogLevelReload {
reload_handle
}


// helpers

fn fmt_entry(entry: &SignedEntry) -> String {
Expand Down

0 comments on commit c4b38e1

Please sign in to comment.