- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了与 Is there any straightforward way for Clap to display help when no command is provided? 相同的问题,但该问题中提出的解决方案对我来说还不够好。
.setting(AppSettings::ArgRequiredElseHelp)
如果没有提供参数则停止程序,即使没有提供参数我也需要程序继续执行。我需要额外显示的帮助。
最佳答案
你可以写之前的字符串。
use clap::{App, SubCommand};
use std::str;
fn main() {
let mut app = App::new("myapp")
.version("0.0.1")
.about("My first CLI APP")
.subcommand(SubCommand::with_name("ls").about("List anything"));
let mut help = Vec::new();
app.write_long_help(&mut help).unwrap();
let _ = app.get_matches();
println!("{}", str::from_utf8(&help).unwrap());
}
或者您可以使用 get_matches_safe
use clap::{App, AppSettings, ErrorKind, SubCommand};
fn main() {
let app = App::new("myapp")
.setting(AppSettings::ArgRequiredElseHelp)
.version("0.0.1")
.about("My first CLI APP")
.subcommand(SubCommand::with_name("ls").about("List anything"));
let matches = app.get_matches_safe();
match matches {
Err(e) => {
if e.kind == ErrorKind::MissingArgumentOrSubcommand {
println!("{}", e.message)
}
}
_ => (),
}
}
关于rust - 调用 Clap 的 get_matches 后如何显示帮助?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54837057/
有没有办法让我们在 clap 的帮助消息中换行? 我尝试了多行注释,还尝试在混合中插入 \n。但两者都不起作用。 #[derive(Parser, Debug)] #[clap(author, ver
我想使用 clap derive API 来解析 Ipv4Addr。 #![allow(unused)] use clap; // 3.1.6 use clap::Parser; use std::n
我正在使用 Clap,我的 YAML 文件包含以下内容: args: - DIRECTORY help: one or more directories required: true
我正在构建一个可以调用其他底层程序的 CLI,这些程序有自己的选项和参数。我希望能够通过 CLI 将这些选项传递给程序。 $ cli --program [PROGRAM] --programOpts
我正在使用 clap,但在尝试解析参数时出现意外行为。 我的命令行工具应该像这样工作 foo -u 例如: foo -u jack echo s foo -u paul ls -al 我需要获取诸
这是一个例子: extern crate clap; use clap::{Arg, App}; fn main() { let args = App::new("test") .arg(Ar
即使阅读了关于引用所有权和借用的章节,我仍然无法理解以下代码中的某些内容,这实际上阻止了我从 clap::App 调用多个方法! extern crate clap; use clap::App; f
假设我有以下命令行: ./app foo bar baz 我想从中取出这个数组: ["foo", "bar", "baz"] 考虑到位置参数可以任意计数,有没有办法在 clap 中做到这一点? 最佳答
作为我的 CLI 工具的一部分,我有一个 clap::Arg取多个值,表示 (x, y)协调。我希望使用能够将值作为 -p/--position 1 0 传递 .arg( clap::Arg:
我正在使用 Clap我正在努力使子命令可以为参数取多个值。我追求的界面是: just use repo [files] 一个例子: just use radar/dot-files gitaliase
我正在使用 the Clap crate用于解析命令行参数。我定义了一个子命令 ls那应该列出文件。 Clap 还定义了一个 help显示有关应用程序及其使用情况的信息的子命令。 如果没有提供命令,则
我目前正在研究 Rust port证券tool .根据 Rust 的指南,我想将核心库隔离到它自己的箱子中,这样我们就可以创建与核心库交互的各种工具(CLI、API、流等),而无需将它们耦合在一起。
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 去年关闭。 Improve th
我有一个使用 Clap 的程序 foo处理命令参数解析。 foo 调用另一个程序 bar。最近,我决定 foo 的用户如果愿意,应该能够将参数传递给 bar。我向 Clap 添加了 bar 命令: l
我正在尝试在 Clap 和 YAML 的帮助下用 Rust 编写 CLI。我的输入将需要一个参数(文件路径)和标志之一 -s、-r 或 -g。标志 -s 和 -r 将需要两个标志之一 -t 和 -m,
问题 我有一个采用不同选项的命令,这些选项的相对顺序对于命令的语义很重要。例如,在 command --config A --some-option --config-file B --random-
我遇到了与 Is there any straightforward way for Clap to display help when no command is provided? 相同的问题,但
我正在学习 Rust 并尝试找到类似实用程序的工具(是的,另一个),我正在使用 clap 并尝试支持程序参数的命令行和配置文件(这与 clap yml 文件无关) . 我正在尝试解析命令,如果没有命令
我有一个鼓掌App像这样: let m = App::new("test") .arg( Arg::with_name("INPUT") .help("
clap crate 为 -h 选项实现了内置行为,但它似乎没有为 -? 做同样的事情。有没有办法告诉它这样做? 最佳答案 我在 clap repository 上开了一个问题.作者/主要贡献者已在那
我是一名优秀的程序员,十分优秀!