#![allow(dead_code)]
use std::str::FromStr;
use clap::Parser;
use clap_stdin::FileOrStdin;
use serde::Deserialize;
#[derive(Clone, Debug, Deserialize)]
struct User {
name: String,
age: u8,
}
impl FromStr for User {
type Err = serde_json::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
serde_json::from_str(s)
}
}
#[derive(Debug, Parser)]
struct Args {
#[arg(default_value = "-")]
user: FileOrStdin<User>,
}
#[cfg(not(feature = "tokio"))]
fn main() -> anyhow::Result<()> {
let args = Args::parse();
eprintln!("{:?}", args.user.contents()?);
Ok(())
}
#[cfg(feature = "tokio")]
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
let args = Args::parse();
eprintln!("{:?}", args.user.contents_async().await?);
Ok(())
}