Commit graph

23 commits

Author SHA1 Message Date
Changyuan Lyu
51e0bc4468 fix(aco)!: report an error if an id is not found
If an id is not found, it is more likely to be a typo than a value
which is serialized to `id_xxxx`. If the later case really happens,
the value can still be represented by the id_ syntax.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-08-01 22:37:58 -07:00
Changyuan Lyu
4c320df2f3 feat(aco): generate help message from trait Help
`help_text` generates the help message at runtime. It cannot be done
at compile time because proc macro cannot access the information of
sub-field types.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-28 13:45:39 -07:00
Changyuan Lyu
54549ce6b6 feat(aco): add trait Help and the derive macro
Trait `Help` returns a description of a type. It is used to generate
the help message for the command line interface.

The derive macro implements `Help` for enums and structs and
includes inline documentation in the description.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-28 13:45:39 -07:00
Changyuan Lyu
c54724c20a fix(aco)!: do not deserialize empty string to None
For a struct like

  struct Foo {
    path: PathBuf,
    param: Option<String>,
  }

to set `param` to `None`, it is more intuitive to write `path=foo`
than `path=foo,param=`. The latter looks more like setting `param` to
`Some("")`.

On the other hand, if the value is an id and the id points to an empty
string, it is interpreted as `None`.

Fixes: 8f3ba3445a ("fix(aco): differentiate `Some("")` from `None`")

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-28 11:35:31 -07:00
Changyuan Lyu
e4197f056f build: move common values to workspace Cargo.toml
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-23 23:13:03 -07:00
Changyuan Lyu
252ec2a6b6 fix(aco): report errors when ignoring inputs
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
86c7c7c5ba fix(aco): deserialize unit and unit_struct
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
f8fe62c678 fix(aco): deserialize byte array
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
f645dc92a4 fix(aco): deserialize a single character
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
51de75e28e fix(aco): deserialize float and signed numbers
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
8f3ba3445a fix(aco): differentiate Some("") from None
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
535ada772e fix(aco): deserialize comma-separated sequences
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
e105cc072e test(aco): deserialize nested values in maps
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
225bb140cf fix(aco): consume top level strings directly
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
e708b4279e fix(aco): allow a string to be referred by an id
This allows a string containing commas or equal signs to be a value
of a map.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
0c82caf3c6 fix(aco): require ids to start with id_
This allows a value of a complex type to be serialized inline, given
its string representation contains neither a comma nor an equal sign.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
3aac5fe7db fix(aco): consume the input with separators
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
aae3d0bda4 fix(aco): change de state on parsing complex types
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
971aadb7ed fix(aco): report an error in deserialize_any()
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-20 17:53:03 -07:00
Changyuan Lyu
7f56e61198 fix(aco): make in-value enum variant aliases work
The array `variants` passed from serde does not contain enum variant
aliases. Thus for an unit_variant that has an alias, the alias name
was interpreted as an object id and the deserialization failed.

On the other hand, for a non-in-value enum value, the full string was
passed to `Enum::new` and somehow serde can determine the variant
from `variant_seed`, even if the string is a variant alias.

Therefore, to make the in-value case work, the value string is always
interpreted as an object id first. If an object string cannot be
found, the object id is interpreted as the object string. In both two
cases, the object string is passed to `Enum::new` to let serde find
out which variant it is.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-13 20:51:40 -07:00
Changyuan Lyu
ab5a08d387 chore: bump version to 0.3.0
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-07-04 16:34:35 -07:00
Changyuan Lyu
3c241aa63e chore: bump version to 0.2.0
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-24 13:56:06 -07:00
Changyuan Lyu
6e97023603 feat(cli): add a new crate for parsing cli opts
`serde-aco` is for parsing complex data structures from command line.
Nested structures can be expressed by multiple key-value pair
strings.

This crate is inspired by QEMU's `-object` flag.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 00:00:14 -07:00