diff options
Diffstat (limited to '')
| -rw-r--r-- | Cargo.lock | 12 | ||||
| -rw-r--r-- | Cargo.toml | 3 | ||||
| -rw-r--r-- | src/main.rs | 14 | 
3 files changed, 25 insertions, 4 deletions
| @@ -518,6 +518,17 @@ dependencies = [  ]  [[package]] +name = "protobuf-json-mapping" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce19fee00c35e62179f79d622f440c27466c9f8dff68ca907d8f59dfc8a88adb" +dependencies = [ + "protobuf", + "protobuf-support", + "thiserror", +] + +[[package]]  name = "protobuf-parse"  version = "3.2.0"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -719,6 +730,7 @@ dependencies = [   "clap",   "protobuf",   "protobuf-codegen", + "protobuf-json-mapping",   "reqwest",   "tokio",  ] @@ -9,7 +9,8 @@ edition = "2021"  protobuf-codegen = "3.2"  [dependencies] -protobuf = "3.2.0" +protobuf = "3.2" +protobuf-json-mapping = "3.2"  reqwest = { version = "0.11", features = ["json", "rustls-tls"], default-features = false }  tokio = { version = "1", features = ["full"] } diff --git a/src/main.rs b/src/main.rs index fd02f82..81a5067 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,10 +9,13 @@ use clap::Parser;  #[command(author, version, about, long_about = None)]  struct Args {     /// uri of the GTFS RT feed to fetch & display -   #[arg(long)]     url: String, +   /// emit the feed as json +   #[arg(long)] +   json: bool  } +  #[tokio::main]  async fn main() -> Result<(), Box<dyn std::error::Error>> {      let args = Args::parse(); @@ -21,8 +24,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {          .bytes().await?;      let proto = FeedMessage::parse_from_bytes(&resp[..])?; -         -    println!("{}", protobuf::text_format::print_to_string_pretty(&proto)); + +    match args.json { +        true =>  +            println!("{}", protobuf_json_mapping::print_to_string(&proto)?), +        false =>  +            println!("{}", protobuf::text_format::print_to_string_pretty(&proto)) +    }      Ok(())  } | 
