mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-25 05:03:05 +00:00
aa043e8c00
Add a crate for deserializing command-line options given as key-values. This crate leverages serde to deserialize key-value argument strings (a commonly used pattern in crosvm) into configuration structures. This will allow us to remove a big part of the manual parsing currently done in `main.rs`, will provide consistent arguments to the `crosvm run` and `crosvm device` commands, and results in more precise error reporting. The use of serde will also allow us to similarly deserialize configuration structures from configuration files with very little extra code involved. As explained in the crate's documentation, its main entry point is a `from_key_values` function that allows a build a struct implementing serde's `Deserialize` trait from a key/values string. In order to integrate transparently with `argh`, there is also a `FromKeyValue` derive macro that automatically implements `FromArgValue` for structs deriving from it. BUG=b:218223240 BUG=b:217480043 TEST=cargo build TEST=cargo test -p serde_keyvalue Change-Id: Id6316e40150d5f08a05e6f04e39ecbc73d72dfa0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3439669 Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org> Reviewed-by: Anton Romanov <romanton@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
773 B
773 B
Serde deserializer from key=value strings
A lightweight serde deserializer for strings containing key-value pairs separated by commas, as commonly found in command-line parameters.
Say your program takes a command-line option of the form:
--foo type=bar,active,nb_threads=8
This crate provides a from_key_values
function that deserializes these key-values into a
configuration structure. Since it uses serde, the same configuration structure can also be created
from any other supported source (such as a TOML or YAML configuration file) that uses the same keys.
Integration with the argh command-line parser is also provided via
the argh_derive
feature.
See the inline documentation for examples and more details.