我有一个像这样的基本结构
pub struct Args {
#[clap(short, long, value_parser)]
pub files: Vec<String>,
}
Run Code Online (Sandbox Code Playgroud)
我试图让这个结构体采用多个这样的值
cargo run -- --files hello world
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,它看不world正确。这是错误的:
error: Found argument 'world' which wasn't expected, or isn't valid in this context
Run Code Online (Sandbox Code Playgroud)
让 clap 填充此结构的正确方法是什么?
在提供的示例中,函数声明PrintBar抛出错误,因为_bar不是编译时常量。避免此问题的最佳做法是什么?
using System;
class Foo
{
private readonly string _bar;
public Foo(string initBar)
{
_bar = initBar;
}
public void PrintBar(string value = _bar)
{
Console.WriteLine(value);
}
}
Run Code Online (Sandbox Code Playgroud)