From f02165aafb179cdb8f27c446fc39ea4f396a8b8d Mon Sep 17 00:00:00 2001
From: Ryan Reed <git@ryanreed.net>
Date: Tue, 12 Jul 2022 20:32:04 -0400
Subject: [PATCH 1/5] Moving store-path to a global argument

---
 src/transpose/console.py | 14 +++++++-------
 tests/test_console.py    |  4 ++--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/transpose/console.py b/src/transpose/console.py
index 96ead32..24ec517 100644
--- a/src/transpose/console.py
+++ b/src/transpose/console.py
@@ -41,6 +41,13 @@ def parse_arguments(args=None):
         """,
     )
     parser.add_argument("--version", action="version", version=f"Transpose {version}")
+    parser.add_argument(
+        "--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
@@ -79,13 +86,6 @@ def parse_arguments(args=None):
         "target_path",
         help="The path to the directory that should be moved to storage",
     )
-    store_parser.add_argument(
-        "--store-path",
-        dest="store_path",
-        nargs="?",
-        default=store_path,
-        help="The path to where the target should be stored (default: %(default)s)",
-    )
 
     return parser.parse_args(args)
 
diff --git a/tests/test_console.py b/tests/test_console.py
index de6eff5..e047a0c 100644
--- a/tests/test_console.py
+++ b/tests/test_console.py
@@ -10,11 +10,11 @@ def test_parse_arguments():
 
     args = parse_arguments(
         [
+            "--store-path",
+            "/mnt/store",
             "store",
             "--cache-filename",
             "test-cache-file.json",
-            "--store-path",
-            "/mnt/store",
             "MyTarget",
             "/tmp/some/path",
         ]

From 9386a507ba7ed7dd41e08683c26f1c813751cc57 Mon Sep 17 00:00:00 2001
From: Ryan Reed <git@ryanreed.net>
Date: Tue, 12 Jul 2022 20:33:45 -0400
Subject: [PATCH 2/5] Using absolute path in cache

---
 src/transpose/utils.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/transpose/utils.py b/src/transpose/utils.py
index fbe7c53..35b95d3 100644
--- a/src/transpose/utils.py
+++ b/src/transpose/utils.py
@@ -41,7 +41,7 @@ def create_cache(cache_path: Path, original_path: Path) -> None:
     Returns:
         None
     """
-    template = {"version": version, "original_path": str(original_path)}
+    template = {"version": version, "original_path": str(original_path.absolute())}
     with open(str(cache_path), "w") as f:
         json.dump(template, f)
 

From ed9a684225152cdbedf15ca9d05e22ed182e9d60 Mon Sep 17 00:00:00 2001
From: Ryan Reed <git@ryanreed.net>
Date: Tue, 12 Jul 2022 20:34:36 -0400
Subject: [PATCH 3/5] Adding support for 'create' action

---
 src/transpose/console.py   | 16 ++++++++++++++++
 src/transpose/transpose.py | 19 +++++++++++++++++++
 tests/test_console.py      | 15 +++++++++++++++
 tests/test_transpose.py    | 29 +++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+)

diff --git a/src/transpose/console.py b/src/transpose/console.py
index 24ec517..795e2b1 100644
--- a/src/transpose/console.py
+++ b/src/transpose/console.py
@@ -15,6 +15,8 @@ def entry_point() -> None:
 
     if args.action == "apply":
         t.apply()
+    elif args.action == "create":
+        t.create(stored_path=args.stored_path)
     elif args.action == "restore":
         t.restore()
     elif args.action == "store":
@@ -63,6 +65,20 @@ def parse_arguments(args=None):
         help="The path to the directory to locate the cache file",
     )
 
+    create_parser = subparsers.add_parser(
+        "create",
+        help="Create the cache file from an already stored path. Only creates the cache file.",
+        parents=[base_parser],
+    )
+    create_parser.add_argument(
+        "target_path",
+        help="The path to the directory that should by a symlink",
+    )
+    create_parser.add_argument(
+        "stored_path",
+        help="The path that is currently stored (the target of the symlink)",
+    )
+
     restore_parser = subparsers.add_parser(
         "restore",
         help="Move a transposed directory back to it's original location, based on the cachefile",
diff --git a/src/transpose/transpose.py b/src/transpose/transpose.py
index 7835c27..1778992 100644
--- a/src/transpose/transpose.py
+++ b/src/transpose/transpose.py
@@ -36,6 +36,25 @@ class Transpose:
 
         symlink(target_path=self.cache_path.parent, symlink_path=original_path)
 
+    def create(self, stored_path: str) -> None:
+        """
+        Create the cache file from the target directory and stored directory
+
+        This is useful if a path is already stored somewhere else but the cache file is missing
+
+        Ideally, the target should a symlink or not exist so a restore or apply can function
+        """
+        stored_path = pathlib.Path(stored_path)
+        if not stored_path.exists():
+            raise TransposeError("Stored path does ")
+
+        self.cache_path = stored_path.joinpath(self.cache_filename)
+
+        create_cache(
+            cache_path=self.cache_path,
+            original_path=self.target_path,
+        )
+
     def restore(self) -> None:
         """
         Restores a previously Transpose managed directory to it's previous location.
diff --git a/tests/test_console.py b/tests/test_console.py
index e047a0c..a601cf9 100644
--- a/tests/test_console.py
+++ b/tests/test_console.py
@@ -33,6 +33,21 @@ def test_parse_arguments_apply():
     assert args.target_path == "/tmp/some/path"
 
 
+def test_parse_arguments_create():
+    # Missing required argument - target_path store_path
+    with pytest.raises(SystemExit):
+        args = parse_arguments(["create"])
+
+    # Missing required argument - stored_path
+    with pytest.raises(SystemExit):
+        args = parse_arguments(["create", "/tmp/target_path"])
+
+    args = parse_arguments(["create", "/tmp/target_path", "/tmp/stored_path"])
+    assert args.action == "create"
+    assert args.target_path == "/tmp/target_path"
+    assert args.stored_path == "/tmp/stored_path"
+
+
 def test_parse_arguments_store():
     # Missing required argument - name (Store)
     with pytest.raises(SystemExit):
diff --git a/tests/test_transpose.py b/tests/test_transpose.py
index 1b56afd..a81e6c0 100644
--- a/tests/test_transpose.py
+++ b/tests/test_transpose.py
@@ -60,6 +60,35 @@ def test_apply():
     assert target_path.is_dir() and target_path.is_symlink()
 
 
+@setup_restore()
+def test_create():
+    target_path = pathlib.Path(TARGET_DIR)
+    stored_path = pathlib.Path(STORE_DIR).joinpath(STORED_DIR)
+
+    t = Transpose(
+        target_path=str(target_path),
+        store_path=str(stored_path),
+    )
+
+    # Missing stored path
+    stored_path.rename("tmp")
+    with pytest.raises(TransposeError):
+        t.create(stored_path=stored_path)
+    pathlib.Path("tmp").rename(stored_path)
+
+    cache_path = stored_path.joinpath(t.cache_filename)
+
+    # Successful Create
+    t.create(stored_path=stored_path)
+    assert t.cache_path == cache_path
+    assert cache_path.exists()
+
+    with open(t.cache_path, "r") as f:
+        cache = json.load(f)
+
+    assert cache["original_path"] == str(target_path.absolute())
+
+
 @setup_store()
 def test_store():
     t = Transpose(

From c0d15bbb848cf68a2a80b51e731333221586019b Mon Sep 17 00:00:00 2001
From: Ryan Reed <git@ryanreed.net>
Date: Tue, 12 Jul 2022 20:35:03 -0400
Subject: [PATCH 4/5] Minor comment update

---
 tests/test_console.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/test_console.py b/tests/test_console.py
index a601cf9..d87d011 100644
--- a/tests/test_console.py
+++ b/tests/test_console.py
@@ -24,7 +24,7 @@ def test_parse_arguments():
 
 
 def test_parse_arguments_apply():
-    # Missing required argument - target_path (Apply)
+    # Missing required argument - target_path
     with pytest.raises(SystemExit):
         args = parse_arguments(["apply"])
 
@@ -49,11 +49,11 @@ def test_parse_arguments_create():
 
 
 def test_parse_arguments_store():
-    # Missing required argument - name (Store)
+    # Missing required argument - name
     with pytest.raises(SystemExit):
         args = parse_arguments(["store"])
 
-    # Missing required argument - target_path (Store)
+    # Missing required argument - target_path
     with pytest.raises(SystemExit):
         args = parse_arguments(["store", "My Name"])
 
@@ -64,7 +64,7 @@ def test_parse_arguments_store():
 
 
 def test_parse_arguments_restore():
-    # Missing required argument - target_path (Restore)
+    # Missing required argument - target_path
     with pytest.raises(SystemExit):
         args = parse_arguments(["restore"])
 

From 21d2c131caa145df5c931b203b6a77b68fb5b5e4 Mon Sep 17 00:00:00 2001
From: Ryan Reed <git@ryanreed.net>
Date: Tue, 12 Jul 2022 20:37:57 -0400
Subject: [PATCH 5/5] Minor comment update

---
 src/transpose/transpose.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/transpose/transpose.py b/src/transpose/transpose.py
index 1778992..df0f4df 100644
--- a/src/transpose/transpose.py
+++ b/src/transpose/transpose.py
@@ -42,7 +42,7 @@ class Transpose:
 
         This is useful if a path is already stored somewhere else but the cache file is missing
 
-        Ideally, the target should a symlink or not exist so a restore or apply can function
+        Ideally, the target should be a symlink or not exist so a restore or apply can function
         """
         stored_path = pathlib.Path(stored_path)
         if not stored_path.exists():