Repository: google/argh (language: rust)

Issue:
Consider making serde dependency optional (as a feature)
First: Thanks for writing & publishing argh as libre software! It's been a joy to use and solves the problem without dependencies. Or at least it used to, hence this issue.

Where I'm coming from: I'm trying to keep my list of dependencies (and my binary size, but that's secondary) as small as possible for my (rust) programs.

My question: Would you consider putting the new serde dependency behind a feature flag? Then I could use argh without having another dependency to audit. Also it looks like my program would save a few bytes in binary size (although in all honesty the binary-size impact of serde seems rather minor, according to [`cargo bloat`](https://github.com/RazrFalcon/cargo-bloat)).

Thanks 🙂 


Discussion / hints:
I'd also be interested in using argh without serde

Fix patch:
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.


Test patch: