From 494cfaa7bfbe0496cea78741d99c0e329cdc31ed Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Tue, 26 Jul 2022 22:26:06 -0400 Subject: [PATCH] BREAKING CHANGE: Moving store_path to only the store action --- README.md | 2 +- src/transpose/console.py | 19 +++++++++---------- src/transpose/transpose.py | 6 ++---- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ba18ef0..1f8c49f 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ transpose restore ~/.local/share/transpose/zsh # Remove symlink, move ~/.local/ transpose apply ~/.local/share/transpose/zsh # Recreate symlink in cache location transpose create ~/.config/zsh ~/.local/share/transpose/zsh # Recreate cache file -transpose -s /mnt/backups store ~/.config/zsh zsh_config # Move ~/.config/zsh -> /mnt/backups/zsh_config, create symlink, create cache +transpose store ~/.config/zsh zsh_config -s /mnt/backups # Move ~/.config/zsh -> /mnt/backups/zsh_config, create symlink, create cache transpose --cache-filename .mycache.json restore /mnt/backups/zsh_config # Use /mnt/backup/.zsh_config.json for restoring a stored directory ``` diff --git a/src/transpose/console.py b/src/transpose/console.py index c1c2e15..9976cd9 100644 --- a/src/transpose/console.py +++ b/src/transpose/console.py @@ -9,7 +9,6 @@ def entry_point() -> None: t = Transpose( target_path=args.target_path, - store_path=args.store_path, cache_filename=args.cache_filename, ) @@ -20,7 +19,7 @@ def entry_point() -> None: elif args.action == "restore": t.restore() elif args.action == "store": - t.store(name=args.name) + t.store(store_path=args.store_path, name=args.name) def parse_arguments(args=None): @@ -43,14 +42,6 @@ def parse_arguments(args=None): """, ) parser.add_argument("--version", action="version", version=f"Transpose {version}") - parser.add_argument( - "-s", - "--store-path", - dest="store_path", - nargs="?", - default=store_path, - help="The path to where the targets should be stored (default: %(default)s)", - ) subparsers = parser.add_subparsers( help="Transpose Action", dest="action", required=True @@ -105,6 +96,14 @@ def parse_arguments(args=None): default=None, help="The name of the directory that will be created in the store path (default: target_path)", ) + store_parser.add_argument( + "-s", + "--store-path", + dest="store_path", + nargs="?", + default=store_path, + help="The path to where the targets should be stored (default: %(default)s)", + ) return parser.parse_args(args) diff --git a/src/transpose/transpose.py b/src/transpose/transpose.py index d2e979b..c359c66 100644 --- a/src/transpose/transpose.py +++ b/src/transpose/transpose.py @@ -8,11 +8,9 @@ class Transpose: def __init__( self, target_path: str, - store_path: str, cache_filename: str = None, ) -> None: self.target_path = pathlib.Path(target_path) - self.store_path = pathlib.Path(store_path) if not cache_filename: cache_filename = ".transpose.json" @@ -86,14 +84,14 @@ class Transpose: new_cache_path = pathlib.Path(original_path).joinpath(self.cache_filename) remove(new_cache_path) - def store(self, name: str = None) -> None: + def store(self, store_path: str, name: str = None) -> None: """ Moves a directory to a central location and creates a symlink to the old path. """ if name is None: name = self.target_path.name - new_location = pathlib.Path(self.store_path).joinpath(name) + new_location = pathlib.Path(store_path).joinpath(name) if not check_path(path=self.target_path): raise TransposeError(