Skip to content

Commit

Permalink
Make serde optional (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
novacrazy authored Apr 9, 2024
1 parent e901d3a commit f02f6b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion argh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion argh_shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
21 changes: 14 additions & 7 deletions argh_shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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>,
Expand All @@ -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]
Expand All @@ -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.
Expand Down

0 comments on commit f02f6b4

Please sign in to comment.