clap-maybe-deser
Provides wrapper types to allow:
- Parse
serdedeserializable objects as a flag via theDesertype forclap. - You can also have your app parse either the flags or the deserializable object by using the
MaybeDesertype. - And with the
MaybeStdinDesertype you can do the above, but the deserializable object can come fromstdinvia theclap-stdincrate. - Also exposes the
CustomDeserializertrait so you can implement with your ownDeserializetype.
Usage
Deser
To parse a serde deserializable object as a flag:
// You can run this example with: ` cargo run --features serde_json --example json_config --`
use Parser;
use ;
use Deserialize;
The help output looks like:

The usage for the CLI looks like:

MaybeDeser
To parse as either flags or a deserializable string:
// You can run this example with: ` cargo run --features serde_json --example maybe_json_config --`
use ;
use ;
use Deserialize;
The help output looks like:

The usage passing json looks like:

The usage passing flags looks like:

MaybeStdinDeser
To parse a deserializable string from stdin, as a flag for the deserializable string or flags:
// You can run this example with: `cargo run --features serde_json,stdin --example maybe_stdin_json_config --`
use ;
use ;
use Deserialize;
The output and usage methods are the exact same as MaybeDeser but now you could also pass in the JSON from stdin:

Custom Implmentations
To support whatever Deserialize friendly implementation you want you can do:
// You can run this example with: `cargo run --example custom_yaml_config --`
use Parser;
use ;
use ;
;
You can see this in action as well:

TODO's
- Support more serde crates out of the box.
- Dynamic naming of the flag for
MaybeDeserandMaybeStdinDeser. - Add support for also reading from a File via
clap-stdin'sFileOrStdin.
Licensing
This project is licensed under both the MIT License and the Apache 2.0 License. See the LICENSE-MIT and LICENSE-APACHE files for details.
This project includes dependencies that are licensed under permissive licenses:
clap: MIT License or Apache 2.0 Licenseclap-stdin: MIT License or Apache 2.0 Licenseserde: MIT License or Apache 2.0 Licenseserde_json: MIT License or Apache 2.0 License