Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make serde optional #188

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading