< 返回版块

sharkLoc 发表于 2022-07-19 15:25

Tags:clap

示例代码如下:

use clap::Parser;

/// title
#[derive(Parser,Debug)]
struct Opt{
    /// count num
    #[clap(long, default_value_t=9)]
    num: i32,
    /// deepth count
    #[clap(long)]
    dep: i32,
    /// tag name
    #[clap(long)]
    tag1: String,
    /// optional args
    #[clap(long)]
    tag2: Option<String>,

}

fn main() {
    let args = Opt::parse();
    println!("{:?}",args);
}

运行指定 --help参数时,展示的参数使用信息如下,这里如何将help参数调整到最后显示呢? 包使用API中没看到这块儿内容 [version = "3.1.18"]。

args_optional 
title

USAGE:
    args_optional [OPTIONS] --dep <DEP> --tag1 <TAG1>

OPTIONS:
        --dep <DEP>      deepth count
    -h, --help           Print help information
        --num <NUM>      count num [default: 9]
        --tag1 <TAG1>    tag name
        --tag2 <TAG2>    optional args

评论区

写评论
作者 sharkLoc 2022-07-19 22:15

好的,感谢指点!

--
👇
Nayaka: 可以设置display_order, 越小越靠前

struct Opt{
    /// count num
    #[clap(long, default_value_t=9, display_order = 1)]
    num: i32,
    /// deepth count
    #[clap(long, display_order = 2)]
    dep: i32,
    /// tag name
    #[clap(long, display_order = 3)]
    tag1: String,
    /// optional args
    #[clap(long, display_order = 4)]
    tag2: Option<String>,

}
Nayaka 2022-07-19 18:18

可以设置display_order, 越小越靠前

struct Opt{
    /// count num
    #[clap(long, default_value_t=9, display_order = 1)]
    num: i32,
    /// deepth count
    #[clap(long, display_order = 2)]
    dep: i32,
    /// tag name
    #[clap(long, display_order = 3)]
    tag1: String,
    /// optional args
    #[clap(long, display_order = 4)]
    tag2: Option<String>,

}
作者 sharkLoc 2022-07-19 15:54

(๑•̀ㅂ•́)و✧,非常感谢!

--
👇
苦瓜小仔:

#[derive(Parser, Debug)]
#[clap(setting = clap::AppSettings::DeriveDisplayOrder)]
struct Opt { ... }

https://github.com/clap-rs/clap/discussions/3694

苦瓜小仔 2022-07-19 15:50
#[derive(Parser, Debug)]
#[clap(setting = clap::AppSettings::DeriveDisplayOrder)]
struct Opt { ... }

https://github.com/clap-rs/clap/discussions/3694

1 共 4 条评论, 1 页