aobatact / clap-serde

Provides a wrapper to deserialize clap app using serde.
Apache License 2.0
22 stars 3 forks source link

OsStr support? #30

Open aobatact opened 2 years ago

aobatact commented 2 years ago

Do we need OsStr support?

epage commented 2 years ago

Most uses of OsStr will be for ArgMatches which is out of the scope of clap-serde.

While the builder API has some parts that accept OsStr, it would mostly be for if someone dynamically generates the value from the system, like providing std::env::current_dir as a default. Since this can't b done with clap-serde, there doesn't seem much value.

However, thinking of the idea I put in #33, if the deserializer was made stateful, users could provide "variables" to be used in different places.

Going back to the std::env::current_dir idea, this could look like

let de = clap_serder::Deserialize::new()
    .register("current_dir", std::env::current_dir());
let cmd = de.deserialize(serde_json::Deserializer::from_str(data);

with data being

{
    "args": [
        {
            "id": "input",
            "default_value": { "variable": "current_dir" }
        }
    ]
}

(inspiration: https://github.com/rust-lang/rfcs/blob/master/text/2906-cargo-workspace-deduplicate.md#package-metadata-can-reference-other-workspace-members)