forked from facebook/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
watchman: rust: implement subscribe method
Summary: adds `Client::subscribe` which is similar in usage to `Client::query`, but returns a subscription handle that will yield file changes as they occur. An example of usage is in `examples/subscribe.rs`. Note that the metadata fields are omitted in this version and commented out; to implement those we need to have an alternative to `serde_json::Value` that can handle the binary strings that watchman produces for some metadata; that will be tackled in the next diff in this stack. Reviewed By: jsgf Differential Revision: D18598229 fbshipit-source-id: 6d89a8544d3571d820855c78c261265465fbe1cb
- Loading branch information
1 parent
8f03f19
commit 69b6772
Showing
4 changed files
with
432 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//! This example shows how to initiate a subscription and print out | ||
//! file changes as they are reported | ||
use std::path::PathBuf; | ||
use structopt::StructOpt; | ||
use watchman_client::prelude::*; | ||
|
||
#[derive(Debug, StructOpt)] | ||
#[structopt(about = "Subscribe to watchman and stream file changes for a path")] | ||
struct Opt { | ||
#[structopt(default_value = ".")] | ||
path: PathBuf, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
if let Err(err) = run().await { | ||
// Print a prettier error than the default | ||
eprintln!("{}", err); | ||
std::process::exit(1); | ||
} | ||
Ok(()) | ||
} | ||
|
||
async fn run() -> Result<(), Box<dyn std::error::Error>> { | ||
let opt = Opt::from_args(); | ||
let client = Connector::new().connect().await?; | ||
let resolved = client | ||
.resolve_root(CanonicalPath::canonicalize(opt.path)?) | ||
.await?; | ||
|
||
let (mut sub, initial) = client | ||
.subscribe::<NameOnly>(&resolved, SubscribeRequest::default()) | ||
.await?; | ||
|
||
println!("{} {:#?}", sub.name(), initial); | ||
loop { | ||
let item = sub.next().await?; | ||
println!("{:#?}", item); | ||
} | ||
} |
Oops, something went wrong.