Browse Source

Reworking 'config update' to allow more general entry updates

pull/11/head
Ryan Reed 1 year ago
parent
commit
1200dc3cdb
5 changed files with 18 additions and 10 deletions
  1. +1
    -0
      README.md
  2. +7
    -3
      src/transpose/console.py
  3. +5
    -3
      src/transpose/transpose.py
  4. +3
    -2
      tests/test_console.py
  5. +2
    -2
      tests/test_transpose.py

+ 1
- 0
README.md View File

@ -116,6 +116,7 @@ transpose config add "NewEntry" "/path/to/location"
transpose config get "NewEntry"
transpose config list
transpose config remove "NewEntry"
transpose config update "NewEntry" "path" "/path/to/new/location"
```


+ 7
- 3
src/transpose/console.py View File

@ -43,7 +43,7 @@ def run(args, config_path) -> None:
t.config.remove(args.name)
t.config.save(config_path)
elif args.config_action == "update":
t.config.update(args.name, args.path)
t.config.update(args.name, args.field_key, args.field_value)
t.config.save(config_path)
@ -205,8 +205,12 @@ def parse_arguments(args=None):
help="The name of the entry in the store path",
)
config_update_parser.add_argument(
"path",
help="The path of the directory that should be symlinked to the store",
"field_key",
help="The config key to be updated",
)
config_update_parser.add_argument(
"field_value",
help="The value to updated in the config",
)
return parser.parse_args(args)


+ 5
- 3
src/transpose/transpose.py View File

@ -1,5 +1,6 @@
from dataclasses import asdict, dataclass, field
from pathlib import Path
from typing import Any
# from typing import Self
@ -77,19 +78,20 @@ class TransposeConfig:
except KeyError:
raise TransposeError(f"'{name}' does not exist in Transpose config entries")
def update(self, name: str, path: str) -> None:
def update(self, name: str, field_key: str, field_value: Any) -> None:
"""
Update an entry by name
Args:
name: The name of the entry (must exist)
path: The path where the entry originally exists
field_key: The key to update
field_value: The value to update
Returns:
None
"""
try:
self.entries[name].path = path
setattr(self.entries[name], field_key, field_value)
except KeyError:
raise TransposeError(f"'{name}' does not exist in Transpose config entries")


+ 3
- 2
tests/test_console.py View File

@ -217,9 +217,10 @@ def test_run_config_remove():
@setup_restore()
def test_run_config_update():
args = RunConfigArgs("update")
args.path = "/var/tmp/something"
args.field_key = "path"
args.field_value = "/var/tmp/something"
run_console(args, TRANSPOSE_CONFIG_PATH)
config = TransposeConfig().load(TRANSPOSE_CONFIG_PATH)
assert config.entries[args.name].path == args.path
assert config.entries[args.name].path == args.field_value

+ 2
- 2
tests/test_transpose.py View File

@ -157,9 +157,9 @@ def test_config_update():
with pytest.raises(
TransposeError, match="does not exist in Transpose config entries"
):
config.update("UnknownEntry", "/some/new/path")
config.update("UnknownEntry", "path", "/some/new/path")
config.update(ENTRY_NAME, "/some/new/path")
config.update(ENTRY_NAME, "path", "/some/new/path")
assert config.entries[ENTRY_NAME].path == "/some/new/path"


Loading…
Cancel
Save