From 23fc942db7a09b508286a530f365a64373e22d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Mon, 12 Dec 2022 15:43:01 +0100 Subject: [PATCH] Warn on empty filters Closes #29 --- e2e_tests/test_repos_find_remote.py | 2 +- src/config.rs | 6 ++++++ src/grm/main.rs | 12 ++++++++++++ src/provider/mod.rs | 4 ++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/e2e_tests/test_repos_find_remote.py b/e2e_tests/test_repos_find_remote.py index 77023be..df395f8 100644 --- a/e2e_tests/test_repos_find_remote.py +++ b/e2e_tests/test_repos_find_remote.py @@ -166,7 +166,7 @@ def test_repos_find_remote_no_filter(provider, configtype, default, use_config): cmd = grm(args) assert cmd.returncode == 0 - assert len(cmd.stderr) == 0 + assert "did not specify any filters" in cmd.stderr.lower() if default or configtype == "toml": output = toml.loads(cmd.stdout) diff --git a/src/config.rs b/src/config.rs index e6ac04d..700384b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -183,6 +183,12 @@ impl Config { filters.access.unwrap_or(false), ); + if filter.empty() { + print_warning( + "The configuration does not contain any filters, so no repos will match", + ); + } + let repos = match config.provider { RemoteProvider::Github => { match provider::Github::new(filter, token, config.api_url) { diff --git a/src/grm/main.rs b/src/grm/main.rs index 67419cf..aa522b4 100644 --- a/src/grm/main.rs +++ b/src/grm/main.rs @@ -55,6 +55,10 @@ fn main() { let filter = provider::Filter::new(args.users, args.groups, args.owner, args.access); + if filter.empty() { + print_warning("You did not specify any filters, so no repos will match"); + } + let worktree = args.worktree == "true"; let repos = match args.provider { @@ -278,6 +282,10 @@ fn main() { filters.access.unwrap_or(false), ); + if filter.empty() { + print_warning("You did not specify any filters, so no repos will match"); + } + let repos = match config.provider { provider::RemoteProvider::Github => { match match provider::Github::new(filter, token, config.api_url) { @@ -383,6 +391,10 @@ fn main() { let filter = provider::Filter::new(args.users, args.groups, args.owner, args.access); + if filter.empty() { + print_warning("You did not specify any filters, so no repos will match"); + } + let worktree = args.worktree == "true"; let repos = match args.provider { diff --git a/src/provider/mod.rs b/src/provider/mod.rs index aee003a..1010665 100644 --- a/src/provider/mod.rs +++ b/src/provider/mod.rs @@ -89,6 +89,10 @@ impl Filter { access, } } + + pub fn empty(&self) -> bool { + self.users.is_empty() && self.groups.is_empty() && !self.owner && !self.access + } } pub enum ApiErrorResponse