Skip to content

Update structopt example to use clap #1849

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

Merged
merged 1 commit into from
Jul 24, 2023
Merged

Update structopt example to use clap #1849

merged 1 commit into from
Jul 24, 2023

Conversation

senekor
Copy link
Contributor

@senekor senekor commented Jul 24, 2023

inspired by #1848

structopt was merged into clap, and quicli doesn't seem necessary anymore for this example since read_to_string was stabilized.

Maybe the Result<(), Box<dyn Error>> in this version is less nice? But I'd say it's pretty common for quick-and-dirty error handling.

@senekor senekor requested a review from a team as a code owner July 24, 2023 15:46
@senekor
Copy link
Contributor Author

senekor commented Jul 24, 2023

Using anyhow might be nice:

use std::fs::read_to_string;

fn main() -> anyhow::Result<()> {
    let args = Cli::parse();
    read_to_string(&args.file)?
        .lines()
        .take(args.num)
        .for_each(|line| println!("{}", line));
    Ok(())
}

@senekor senekor changed the title Update structop example to use clap Update structopt example to use clap Jul 24, 2023
@Manishearth Manishearth merged commit ee419ce into rust-lang:master Jul 24, 2023
@Manishearth
Copy link
Member

Manishearth commented Jul 24, 2023

Would be nice to get the CLI WG to sign off on this but I think they don't really exist anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants