Skip to content

Commit

Permalink
fix!: use plural names for options (#267)
Browse files Browse the repository at this point in the history
Consistently uses singular and plural names for options in config and
CLI

BREAKING CHANGE: This requires to adapt CLI calls and config keys.

Affected options:
- `glob` -> `globs` in config profile
- `iglob` -> `iglobs` in config profile
- `glob`-file -> `glob-files` in config profile
- `iglob-file` -> `iglob-files` in config profile
- `custom-ignore-file` -> `custom-ignore-files` in config profile
- `tag`-> `tags` in config profile
- `keep-tags` -> now only array
- `keep-ids` -> now only array

---------

Co-authored-by: simonsan <14062932+simonsan@users.noreply.github.com>
  • Loading branch information
aawsome and simonsan authored Sep 22, 2024
1 parent 43fffbe commit e7edd4d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 35 deletions.
41 changes: 19 additions & 22 deletions crates/core/src/backend/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
path::{Path, PathBuf},
};

use serde_with::{serde_as, DisplayFromStr, OneOrMany};
use serde_with::{serde_as, DisplayFromStr};

use bytesize::ByteSize;
#[cfg(not(windows))]
Expand Down Expand Up @@ -68,28 +68,24 @@ pub struct LocalSourceSaveOptions {
/// [`LocalSourceFilterOptions`] allow to filter a local source by various criteria.
pub struct LocalSourceFilterOptions {
/// Glob pattern to exclude/include (can be specified multiple times)
#[cfg_attr(feature = "clap", clap(long))]
#[cfg_attr(feature = "clap", clap(long = "glob", value_name = "GLOB"))]
#[cfg_attr(feature = "merge", merge(strategy = merge::vec::overwrite_empty))]
#[serde_as(as = "OneOrMany<_>")]
pub glob: Vec<String>,
pub globs: Vec<String>,

/// Same as --glob pattern but ignores the casing of filenames
#[cfg_attr(feature = "clap", clap(long, value_name = "GLOB"))]
#[cfg_attr(feature = "clap", clap(long = "iglob", value_name = "GLOB"))]
#[cfg_attr(feature = "merge", merge(strategy = merge::vec::overwrite_empty))]
#[serde_as(as = "OneOrMany<_>")]
pub iglob: Vec<String>,
pub iglobs: Vec<String>,

/// Read glob patterns to exclude/include from this file (can be specified multiple times)
#[cfg_attr(feature = "clap", clap(long, value_name = "FILE"))]
#[cfg_attr(feature = "clap", clap(long = "glob-file", value_name = "FILE"))]
#[cfg_attr(feature = "merge", merge(strategy = merge::vec::overwrite_empty))]
#[serde_as(as = "OneOrMany<_>")]
pub glob_file: Vec<String>,
pub glob_files: Vec<String>,

/// Same as --glob-file ignores the casing of filenames in patterns
#[cfg_attr(feature = "clap", clap(long, value_name = "FILE"))]
#[cfg_attr(feature = "clap", clap(long = "iglob-file", value_name = "FILE"))]
#[cfg_attr(feature = "merge", merge(strategy = merge::vec::overwrite_empty))]
#[serde_as(as = "OneOrMany<_>")]
pub iglob_file: Vec<String>,
pub iglob_files: Vec<String>,

/// Ignore files based on .gitignore files
#[cfg_attr(feature = "clap", clap(long))]
Expand All @@ -102,15 +98,16 @@ pub struct LocalSourceFilterOptions {
pub no_require_git: bool,

/// Treat the provided filename like a .gitignore file (can be specified multiple times)
#[cfg_attr(feature = "clap", clap(long, value_name = "FILE"))]
#[cfg_attr(
feature = "clap",
clap(long = "custom-ignorefile", value_name = "FILE")
)]
#[cfg_attr(feature = "merge", merge(strategy = merge::vec::overwrite_empty))]
#[serde_as(as = "OneOrMany<_>")]
pub custom_ignorefile: Vec<String>,
pub custom_ignorefiles: Vec<String>,

/// Exclude contents of directories containing this filename (can be specified multiple times)
#[cfg_attr(feature = "clap", clap(long, value_name = "FILE"))]
#[cfg_attr(feature = "merge", merge(strategy = merge::vec::overwrite_empty))]
#[serde_as(as = "OneOrMany<_>")]
pub exclude_if_present: Vec<String>,

/// Exclude other file systems, don't cross filesystem boundaries and subvolumes
Expand Down Expand Up @@ -157,13 +154,13 @@ impl LocalSource {

let mut override_builder = OverrideBuilder::new("");

for g in &filter_opts.glob {
for g in &filter_opts.globs {
_ = override_builder
.add(g)
.map_err(IgnoreErrorKind::GenericError)?;
}

for file in &filter_opts.glob_file {
for file in &filter_opts.glob_files {
for line in std::fs::read_to_string(file)
.map_err(|err| IgnoreErrorKind::ErrorGlob {
file: file.into(),
Expand All @@ -180,13 +177,13 @@ impl LocalSource {
_ = override_builder
.case_insensitive(true)
.map_err(IgnoreErrorKind::GenericError)?;
for g in &filter_opts.iglob {
for g in &filter_opts.iglobs {
_ = override_builder
.add(g)
.map_err(IgnoreErrorKind::GenericError)?;
}

for file in &filter_opts.iglob_file {
for file in &filter_opts.iglob_files {
for line in std::fs::read_to_string(file)
.map_err(|err| IgnoreErrorKind::ErrorGlob {
file: file.into(),
Expand All @@ -200,7 +197,7 @@ impl LocalSource {
}
}

for file in &filter_opts.custom_ignorefile {
for file in &filter_opts.custom_ignorefiles {
_ = walk_builder.add_custom_ignore_filename(file);
}

Expand Down
7 changes: 3 additions & 4 deletions crates/core/src/commands/forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use chrono::{DateTime, Datelike, Duration, Local, Timelike};
use derive_setters::Setters;
use serde_derive::{Deserialize, Serialize};
use serde_with::{serde_as, skip_serializing_none, DisplayFromStr, OneOrMany};
use serde_with::{serde_as, skip_serializing_none, DisplayFromStr};

use crate::{
error::{CommandErrorKind, RusticResult},
Expand Down Expand Up @@ -113,14 +113,13 @@ pub struct KeepOptions {
/// Keep snapshots with this taglist (can be specified multiple times)
#[cfg_attr(feature = "clap", clap(long, value_name = "TAG[,TAG,..]"))]
#[cfg_attr(feature = "merge", merge(strategy=merge::vec::overwrite_empty))]
#[serde_as(as = "OneOrMany<DisplayFromStr>")]
#[serde_as(as = "Vec<DisplayFromStr>")]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub keep_tags: Vec<StringList>,

/// Keep snapshots ids that start with ID (can be specified multiple times)
#[cfg_attr(feature = "clap", clap(long = "keep-id", value_name = "ID"))]
#[cfg_attr(feature = "merge", merge(strategy=merge::vec::overwrite_empty))]
#[serde_as(as = "OneOrMany<_>")]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub keep_ids: Vec<String>,

Expand Down Expand Up @@ -716,7 +715,7 @@ mod tests {
.map(|(time, tags)| -> Result<_> {
let opts = &crate::SnapshotOptions::default()
.time(parse_time(time)?)
.tag(vec![StringList::from_str(tags)?]);
.tags(vec![StringList::from_str(tags)?]);
Ok(SnapshotFile::from_options(opts)?)
}),
)
Expand Down
15 changes: 7 additions & 8 deletions crates/core/src/repofile/snapshotfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use itertools::Itertools;
use log::info;
use path_dedot::ParseDot;
use serde_derive::{Deserialize, Serialize};
use serde_with::{serde_as, skip_serializing_none, DisplayFromStr, OneOrMany};
use serde_with::{serde_as, skip_serializing_none, DisplayFromStr};

use crate::{
backend::{decrypt::DecryptReadBackend, FileType, FindInBackend},
Expand Down Expand Up @@ -53,10 +53,9 @@ pub struct SnapshotOptions {
pub label: Option<String>,

/// Tags to add to snapshot (can be specified multiple times)
#[cfg_attr(feature = "clap", clap(long, value_name = "TAG[,TAG,..]"))]
#[serde_as(as = "OneOrMany<DisplayFromStr>")]
#[cfg_attr(feature = "clap", clap(long = "tag", value_name = "TAG[,TAG,..]"))]
#[cfg_attr(feature = "merge", merge(strategy = merge::vec::overwrite_empty))]
pub tag: Vec<StringList>,
pub tags: Vec<StringList>,

/// Add description to snapshot
#[cfg_attr(feature = "clap", clap(long, value_name = "DESCRIPTION"))]
Expand Down Expand Up @@ -109,7 +108,7 @@ impl SnapshotOptions {
///
/// [`SnapshotFileErrorKind::NonUnicodeTag`]: crate::error::SnapshotFileErrorKind::NonUnicodeTag
pub fn add_tags(mut self, tag: &str) -> RusticResult<Self> {
self.tag.push(StringList::from_str(tag)?);
self.tags.push(StringList::from_str(tag)?);
Ok(self)
}

Expand Down Expand Up @@ -412,7 +411,7 @@ impl SnapshotFile {
);
}

_ = snap.set_tags(opts.tag.clone());
_ = snap.set_tags(opts.tags.clone());

Ok(snap)
}
Expand Down Expand Up @@ -1252,8 +1251,8 @@ mod tests {

#[test]
fn test_add_tags() -> Result<()> {
let tag = vec![StringList::from_str("abc")?];
let mut snap = SnapshotFile::from_options(&SnapshotOptions::default().tag(tag))?;
let tags = vec![StringList::from_str("abc")?];
let mut snap = SnapshotFile::from_options(&SnapshotOptions::default().tags(tags))?;
let tags = StringList::from_str("def,abc")?;
assert!(snap.add_tags(vec![tags]));
let expected = StringList::from_str("abc,def")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ fn test_backup_with_tar_gz_passes(
let repo = repo.to_indexed_ids()?;
// third backup with tags and explicitely given parent
let snap = SnapshotOptions::default()
.tag([StringList::from_str("a,b")?])
.tags([StringList::from_str("a,b")?])
.to_snapshot()?;
let opts = opts.parent_opts(ParentOptions::default().parent(second_snapshot.id.to_string()));
let third_snapshot = repo.backup(&opts, paths, snap)?;
Expand Down

0 comments on commit e7edd4d

Please sign in to comment.