diff --git a/src/attribute.rs b/src/attribute.rs index 4ec813f076..51ba559049 100644 --- a/src/attribute.rs +++ b/src/attribute.rs @@ -13,8 +13,8 @@ pub(crate) enum Attribute<'src> { Doc(Option>), Extension(StringLiteral<'src>), Group(StringLiteral<'src>), - Linux, - Macos, + Linux { inverted: bool }, + Macos { inverted: bool }, NoCd, NoExitMessage, NoQuiet, @@ -22,8 +22,8 @@ pub(crate) enum Attribute<'src> { PositionalArguments, Private, Script(Option>), - Unix, - Windows, + Unix { inverted: bool }, + Windows { inverted: bool }, WorkingDirectory(StringLiteral<'src>), } @@ -80,8 +80,8 @@ impl<'src> Attribute<'src> { AttributeDiscriminant::Doc => Self::Doc(arguments.into_iter().next()), AttributeDiscriminant::Extension => Self::Extension(arguments.into_iter().next().unwrap()), AttributeDiscriminant::Group => Self::Group(arguments.into_iter().next().unwrap()), - AttributeDiscriminant::Linux => Self::Linux, - AttributeDiscriminant::Macos => Self::Macos, + AttributeDiscriminant::Linux => Self::Linux { inverted: false }, + AttributeDiscriminant::Macos => Self::Macos { inverted: false }, AttributeDiscriminant::NoCd => Self::NoCd, AttributeDiscriminant::NoExitMessage => Self::NoExitMessage, AttributeDiscriminant::NoQuiet => Self::NoQuiet, @@ -95,8 +95,8 @@ impl<'src> Attribute<'src> { arguments: arguments.collect(), }) }), - AttributeDiscriminant::Unix => Self::Unix, - AttributeDiscriminant::Windows => Self::Windows, + AttributeDiscriminant::Unix => Self::Unix { inverted: false }, + AttributeDiscriminant::Windows => Self::Windows { inverted: false }, AttributeDiscriminant::WorkingDirectory => { Self::WorkingDirectory(arguments.into_iter().next().unwrap()) } @@ -118,28 +118,34 @@ impl<'src> Attribute<'src> { impl Display for Attribute<'_> { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "{}", self.name())?; + let name = self.name(); match self { Self::Confirm(Some(argument)) | Self::Doc(Some(argument)) | Self::Extension(argument) | Self::Group(argument) - | Self::WorkingDirectory(argument) => write!(f, "({argument})")?, - Self::Script(Some(shell)) => write!(f, "({shell})")?, + | Self::WorkingDirectory(argument) => write!(f, "{name}({argument})")?, + Self::Script(Some(shell)) => write!(f, "{name}({shell})")?, + Self::Linux { inverted } + | Self::Macos { inverted } + | Self::Unix { inverted } + | Self::Windows { inverted } => { + if *inverted { + write!(f, "not({name})")?; + } else { + write!(f, "{name}")?; + } + } Self::Confirm(None) | Self::Doc(None) - | Self::Linux - | Self::Macos | Self::NoCd | Self::NoExitMessage | Self::NoQuiet | Self::Openbsd | Self::PositionalArguments | Self::Private - | Self::Script(None) - | Self::Unix - | Self::Windows => {} + | Self::Script(None) => write!(f, "{name}")?, } Ok(())