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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions templates/components/what/cli/code-inputs.html.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use clap::Parser;

/// Read some lines of a file
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
struct Cli {
/// Input file to read
file: String,
/// Number of lines to read
#[structopt(short = "n")]
#[structopt(short = 'n')]
num: usize,
}
9 changes: 4 additions & 5 deletions templates/components/what/cli/code-main.html.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use quicli::prelude::*;
use structopt::StructOpt;
use std::{error::Error, fs::read_to_string};

fn main() -> CliResult {
let args = Cli::from_args();
read_file(&args.file)?
fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::parse();
read_to_string(&args.file)?
.lines()
.take(args.num)
.for_each(|line| println!("{}", line));
Expand Down