Skip to content

using friendly format for claps help message #178

Answered by BurntSushi
junapur asked this question in Q&A
Discussion options

You must be logged in to vote

You probably need a wrapper type here. Clap is probably just using the standard Display impl for Span, which will emit the ISO 8601 format for interoperability reasons. You can do {span:#} to get the "alternate" impl, and that will emit the friendly format.

Example:

use clap::Parser;
use jiff::{Span, ToSpan};

#[derive(Parser)]
#[command(version, about)]
struct Args {
    #[arg(short, long, default_value_t = FriendlySpan(5.minutes()))]
    time: FriendlySpan,
}

fn main() {
    let args = Args::parse();
    println!("{}", args.time.0);
}

#[derive(Clone, Copy, Debug)]
struct FriendlySpan(Span);

impl std::fmt::Display for FriendlySpan {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by junapur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants