From d2ec0f58e0b51c3cc640396dbf0e3f92d29f92be Mon Sep 17 00:00:00 2001 From: Peter Rice Date: Mon, 26 Aug 2024 00:47:57 -0400 Subject: [PATCH] remove launch's --create flag --- CHANGELOG.md | 3 ++- src/qbpm/main.py | 5 +---- src/qbpm/operations.py | 8 +++----- src/qbpm/profiles.py | 6 +----- tests/test_profiles.py | 29 ----------------------------- 5 files changed, 7 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 814a605..3f98c86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,9 @@ - added `-C` argument to reference qutebrowser configs from an arbitrary dir - added `click`-generated completions for bash and zsh - added option support to fish completions + - removed `--create` from `qbpm launch` # 1.0-rc2: - `choose`: builtin support for `fzf` and `fuzzel` - moved argument handling to click - - `qbpm launch`'s -n/--new renamed to -c/--create + - `qbpm launch`'s `-n`/`--new` renamed to `-c`/`--create` diff --git a/src/qbpm/main.py b/src/qbpm/main.py index 60340d4..97448a2 100644 --- a/src/qbpm/main.py +++ b/src/qbpm/main.py @@ -122,9 +122,6 @@ def from_session( @click.option( "-f", "--foreground", is_flag=True, help="Run qutebrowser in the foreground." ) -@click.option( - "-c", "--create", is_flag=True, help="Create the profile if it does not exist." -) @click.pass_obj def launch(context: Context, profile_name: str, **kwargs: Any) -> None: """Launch qutebrowser with a specific profile. All QB_ARGS are passed on to qutebrowser.""" @@ -194,7 +191,7 @@ def then_launch( ) -> None: exit_with( operation(profile, **kwargs) - and ((not launch) or operations.launch(profile, False, foreground, qb_args)) + and ((not launch) or operations.launch(profile, foreground, qb_args)) ) diff --git a/src/qbpm/operations.py b/src/qbpm/operations.py index eb5064f..581234d 100644 --- a/src/qbpm/operations.py +++ b/src/qbpm/operations.py @@ -28,10 +28,8 @@ def from_session( return True -def launch( - profile: Profile, create: bool, foreground: bool, qb_args: tuple[str, ...] -) -> bool: - if not profiles.ensure_profile_exists(profile, create, desktop_file=True): +def launch(profile: Profile, foreground: bool, qb_args: tuple[str, ...]) -> bool: + if not profiles.exists(profile): return False args = profile.cmdline() + list(qb_args) @@ -110,7 +108,7 @@ def choose( return launch_qutebrowser(foreground, qb_args) elif selection: profile = Profile(selection, profile_dir) - return launch(profile, False, foreground, qb_args) + return launch(profile, foreground, qb_args) else: error("no profile selected") return False diff --git a/src/qbpm/profiles.py b/src/qbpm/profiles.py index 07ebebf..9789ec0 100644 --- a/src/qbpm/profiles.py +++ b/src/qbpm/profiles.py @@ -75,14 +75,10 @@ def create_desktop_file(profile: Profile) -> None: desktop.write() -def ensure_profile_exists( - profile: Profile, create: bool = True, desktop_file: bool = False -) -> bool: +def exists(profile: Profile) -> bool: if profile.root.exists() and not profile.root.is_dir(): error(f"{profile.root} is not a directory") return False - if not profile.root.exists() and create: - return new_profile(profile, desktop_file=desktop_file) if not profile.root.exists(): error(f"{profile.root} does not exist") return False diff --git a/tests/test_profiles.py b/tests/test_profiles.py index 216b1ce..7388050 100644 --- a/tests/test_profiles.py +++ b/tests/test_profiles.py @@ -74,35 +74,6 @@ def test_overwrite_config(tmp_path: Path): raise AssertionError() -def test_ensure_profile_exists_exists(tmp_path: Path): - profile = Profile("test", tmp_path, tmp_path) - profile.root.mkdir() - assert profiles.ensure_profile_exists(profile, False) - assert profiles.ensure_profile_exists(profile, True) - check_is_empty(profile.root) - - -def test_ensure_profile_exists_does_not_exist(tmp_path: Path): - assert not profiles.ensure_profile_exists( - Profile("test", tmp_path, tmp_path), False - ) - check_is_empty(tmp_path) - - -def test_ensure_profile_exists_not_dir(tmp_path: Path): - profile = Profile("test", tmp_path, tmp_path) - profile.root.touch() - assert not profiles.ensure_profile_exists(profile, False) - assert not profiles.ensure_profile_exists(profile, True) - - -def test_ensure_profile_exists_create(tmp_path: Path): - (tmp_path / "config.py").touch() - profile = Profile("test", tmp_path, tmp_path) - assert profiles.ensure_profile_exists(profile, True) - check_new_profile(profile) - - def test_new_profile(tmp_path: Path): (tmp_path / "config.py").touch() profile = Profile("test", tmp_path / "test") -- 2.51.2