![](/img/trans.png)
[英]Unable to provide CLI arguments to `cargo test`
我曾經能夠從命令行界面運行特定的命名測試,如下所示: cargo test <test_name> 。 但是現在這給了我錯誤 cargo test的其他論據也不起作用。 導致錯誤的行是測試設置中的這一行: let cli_default_args = Arc::new(cli_a ...
[英]Unable to provide CLI arguments to `cargo test`
我曾經能夠從命令行界面運行特定的命名測試,如下所示: cargo test <test_name> 。 但是現在這給了我錯誤 cargo test的其他論據也不起作用。 導致錯誤的行是測試設置中的這一行: let cli_default_args = Arc::new(cli_a ...
[英]How to create nested subcommands with structopt?
介紹我目前有使用structopt的子命令,與其他答案類似。 但是,我希望嵌套子命令類似於docker的工作方式: 當前代碼 main.rsmod cli; use structopt::StructOpt; use crate::cli::{Opt, Command}; fn main() ...
[英]structopt unable to find its Args parser when defined in a separate file
我開始使用 Rust 中的命令行工具,並從一開始就碰壁。 如果Opt結構是在main.rs定義的,我可以使用StructOpt解析命令行參數,但是由於我希望能夠將Opt結構傳遞到庫代碼中,我將它定義在它自己的文件中,以便其他部分圖書館的人都知道這是怎么回事。 這是轉儲錯誤最少的代碼版本,盡管我承認 ...
[英]Can you build a structopt parser that takes the rest of the command line (or multiple arguments)?
structopt有一個巧妙的功能,它可以接受Vec<T>的類型化參數,這將吞噬命令行的 rest。#[structopt(long, short)] values: Vec<u32>, 它還具有接受您創建的類型的能力, 如果字段類型沒有FromStr實現,或者您想提供 ...
[英]structopt: error[E0277]: the trait bound `String: From<&OsStr>`
我正在使用 Rust 的structopt crate ,但是當我嘗試編譯示例時出現以下錯誤,error[E0277]: the trait bound `String: From<&OsStr>` is not satisfied --> bin/seq.rs:2 ...
[英]Getting relative order of different command line options using clap & structopt
問題我有一個帶有不同選項的命令,這些選項的相對順序對命令的語義很重要。 例如,在command --config A --some-option --config-file B --random-option --config C --another-option --more-options -- ...
[英]How to create a StructOpt command where all subcomands are optional
我想安排如下子命令: mycmd status :打印一個簡短的狀態 - NOT WORKING mycmd status full :打印詳細狀態 - OK mycmd status dump :將完整的調試狀態轉儲到文件中 - 確定我無法獲得簡單的mycmd status ,因為 Stru ...
[英]Rustlang structopt How to set the home directory
我正在為我的 cli 程序使用 crate structopt 。 如果 args 中的 output 目錄未通過,我想將主目錄設置為默認目錄。 以下是我的代碼,請建議我如何實施。 ...
[英]StructOpt - how to provide a default value for a Vec?
我正在尋找一種默認情況下用多個項目初始化structopt Vec字段的方法。 我可以為單個項目做到這一點: use structopt::StructOpt; #[derive(Debug, StructOpt)] pub struct Cli { #[structopt(default ...
[英]Is it possible to construct a StructOpt Args object without parsing command line params for testing?
我有一個 fn main 正在通過 StructOpt 解析 arguments .. Args::from_args。 有沒有辦法創建這個 Args object 而無需實際啟動可執行文件進行測試? 我可以直接創建一個 Args object 嗎? 例如,我可以這樣做嗎 ...
[英]How to pass special characters as string argument using structopt?
我有一個命令行來搜索文件中的單詞。 我正在使用 StructOpt 來獲取用戶想要搜索的單詞。#[derive(Debug, StructOpt)] pub struct Command { pub word_to_search: Option<String>, } 當您編寫 ...
[英]How can I access a runtime-defined variable in stuctopt definitions?
我希望能夠使用變量的值(或者更好的是function(arg)的返回)作為使用 structopt 定義的 CLI 程序的 about 字符串。 最終目標是一個完全本地化的 CLI,它可以檢測系統語言或 ENV var,並加載本地化的字符串,這些字符串會被烘焙到--help消息等中。 默認情況下, ...
[英]How can I pass version information from Vergen to StructOpt?
我正在嘗試在 Rust 中設置一個簡單的 CLI 程序,但我希望它根據git describe的信息而不是 Cargo.toml 文件中的信息顯示版本。 我設置了一些基本的依賴項: 一個 build.rs 文件使用 vergen 進行提升:extern crate vergen; use ver ...
[英]StructOpt: how to combine all arguments in a single string?
我想要做的是將用戶提供的命令行參數作為單個字符串訪問。 首先,我這樣做: 但是后來我決定嘗試用structopt來做它structopt卡住了。 使用structopt是否有可能達到預期的結果,我該怎么做? ...
[英]How to use a CLI argument after subcommand with the structopt crate?
例如,運行我的應用程序 ./app --foo=bar get 效果很好,但是 ./app get --foo=bar 產生錯誤: error: Found argument '--foo' which wasn't expected, or isn't valid in this cont ...
[英]How to attach possible_values to a struct with structopt?
clap允許您像這樣使用possible_values提供可接受值的列表。let mode_vals = ["fast", "slow"]; .possible_values(&mode_vals) 如何使用structopt做到這一點? ...
[英]Define a custom parser using structopt that changes based on another flag
我使用structopt來解析rust應用程序的命令行參數。 有問題的標志如下: query (位置)和case_sensitive (可選)。 #[derive(StructOpt, Debug)] pub struct Config { /// Query to search f ...
[英]How can I distinguish a multi-occurence option from a subsequent optional argument with structopt?
我正在使用structopt定義可以使用的參數 mfe -s opt1 -s opt2 -s opt2 this_is_an_argument 要么 mfe -s opt1 opt2 opt3 this_is_an_argument 問題在於this_is_an_argument ...
[英]How can I use enums in structopt?
我想讓StructOpt與枚舉StructOpt工作,這樣每次用戶通過-d sunday它都會被解析為Day::Sunday : 我目前最好的解決方案是使用Option<String>作為類型並傳遞自定義parse_day() : ...
[英]proc-macro panic with structopt using required_unless and conflicts_with
我想有兩個相互沖突的選項,但還必須選擇其中一個: 這是編譯器(v1.28.0)抱怨的地方: error: proc-macro derive panicked --> src/main.rs:6:10 | 6 | #[derive(StructOpt)] | ...