-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
100 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,62 @@ | ||
use serde_derive::Deserialize; | ||
|
||
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; | ||
|
||
#[derive(Clone, Debug, Copy, Default)] | ||
pub enum LineMode { | ||
#[default] | ||
Size, | ||
MTime, | ||
SizeMTime, | ||
bitflags::bitflags! { | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)] | ||
#[serde(transparent)] | ||
pub struct LineMode: u8 { | ||
const size = 1 << 0; | ||
const mtime = 1 << 1; | ||
const user = 1 << 2; | ||
const group = 1 << 3; | ||
const perm = 1 << 4; | ||
} | ||
} | ||
|
||
impl Default for LineMode { | ||
fn default() -> Self { | ||
Self::size | ||
} | ||
} | ||
|
||
impl LineMode { | ||
pub fn from_string(name: &str) -> JoshutoResult<LineMode> { | ||
match name { | ||
"size" => Ok(LineMode::Size), | ||
"mtime" => Ok(LineMode::MTime), | ||
"sizemtime" => Ok(LineMode::SizeMTime), | ||
_ => Err(JoshutoError::new( | ||
JoshutoErrorKind::InvalidParameters, | ||
format!("Linemode '{}' unknown.", name), | ||
)), | ||
"all" => Ok(LineMode::all()), | ||
"none" => Ok(LineMode::empty()), | ||
_ => { | ||
let mut flags = name.split('|'); | ||
|
||
let mut linemode = LineMode::empty(); | ||
|
||
flags.try_for_each(|flag| { | ||
match flag.trim() { | ||
"size" => linemode |= LineMode::size, | ||
"mtime" => linemode |= LineMode::mtime, | ||
"user" => linemode |= LineMode::user, | ||
"group" => linemode |= LineMode::group, | ||
"perm" => linemode |= LineMode::perm, | ||
flag => { | ||
return Err(JoshutoError::new( | ||
JoshutoErrorKind::InvalidParameters, | ||
format!("Linemode '{}' unknown.", flag), | ||
)) | ||
} | ||
} | ||
|
||
Ok(()) | ||
})?; | ||
|
||
Ok(linemode) | ||
} | ||
} | ||
} | ||
|
||
pub fn as_str(&self) -> &'static str { | ||
match self { | ||
Self::Size => "size", | ||
Self::MTime => "mtime", | ||
Self::SizeMTime => "sizemtime", | ||
} | ||
pub fn as_string(&self) -> String { | ||
self.iter_names() | ||
.map(|f| f.0) | ||
.collect::<Vec<_>>() | ||
.join(" | ") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters