From 50b6d918494766e0a5e0e1cfe42a9435cb008607 Mon Sep 17 00:00:00 2001 From: novacrazy Date: Sun, 7 Apr 2024 14:47:38 -0500 Subject: [PATCH] Make serde optional --- argh/Cargo.toml | 3 ++- argh_shared/Cargo.toml | 2 +- argh_shared/src/lib.rs | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/argh/Cargo.toml b/argh/Cargo.toml index b310dd4..be9b44a 100644 --- a/argh/Cargo.toml +++ b/argh/Cargo.toml @@ -20,5 +20,6 @@ once_cell = "1.10.0" trybuild = "1.0.63" [features] -default = ["help"] +default = ["help", "serde"] help = ["argh_derive/help"] +serde = ["argh_shared/serde"] diff --git a/argh_shared/Cargo.toml b/argh_shared/Cargo.toml index 8e07308..de65044 100644 --- a/argh_shared/Cargo.toml +++ b/argh_shared/Cargo.toml @@ -9,4 +9,4 @@ repository = "https://github.com/google/argh" readme = "README.md" [dependencies] -serde = { version = "1", features = ["derive"] } +serde = { version = "1", optional = true, features = ["derive"] } diff --git a/argh_shared/src/lib.rs b/argh_shared/src/lib.rs index c9306e0..ae44e5b 100644 --- a/argh_shared/src/lib.rs +++ b/argh_shared/src/lib.rs @@ -15,7 +15,8 @@ pub struct CommandInfo<'a> { } /// Information about the command line arguments for a given command. -#[derive(Debug, Default, PartialEq, Eq, Clone, serde::Serialize)] +#[derive(Debug, Default, PartialEq, Eq, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] pub struct CommandInfoWithArgs<'a> { /// The name of the command. pub name: &'a str, @@ -36,7 +37,8 @@ pub struct CommandInfoWithArgs<'a> { } /// Information about a documented error code. -#[derive(Debug, PartialEq, Eq, serde::Serialize)] +#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] pub struct ErrorCodeInfo<'a> { /// The code value. pub code: i32, @@ -45,7 +47,8 @@ pub struct ErrorCodeInfo<'a> { } /// Information about positional arguments -#[derive(Debug, PartialEq, Eq, serde::Serialize)] +#[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] pub struct PositionalInfo<'a> { /// Name of the argument. pub name: &'a str, @@ -63,7 +66,8 @@ pub struct PositionalInfo<'a> { /// Dynamic subcommands do not implement /// get_args_info(), so the command field /// only contains the name and description. -#[derive(Debug, Default, PartialEq, Eq, Clone, serde::Serialize)] +#[derive(Debug, Default, PartialEq, Eq, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] pub struct SubCommandInfo<'a> { /// The subcommand name. pub name: &'a str, @@ -72,7 +76,8 @@ pub struct SubCommandInfo<'a> { } /// Information about a flag or option. -#[derive(Debug, Default, PartialEq, Eq, serde::Serialize)] +#[derive(Debug, Default, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] pub struct FlagInfo<'a> { /// The kind of flag. pub kind: FlagInfoKind<'a>, @@ -92,7 +97,8 @@ pub struct FlagInfo<'a> { } /// The kind of flags. -#[derive(Debug, Default, PartialEq, Eq, serde::Serialize)] +#[derive(Debug, Default, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] pub enum FlagInfoKind<'a> { /// switch represents a boolean flag, #[default] @@ -104,7 +110,8 @@ pub enum FlagInfoKind<'a> { /// The optionality defines the requirements related /// to the presence of the argument on the command line. -#[derive(Debug, Default, PartialEq, Eq, serde::Serialize)] +#[derive(Debug, Default, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] pub enum Optionality { /// Required indicates the argument is required /// exactly once.