Skip to content

Commit 4780acb

Browse files
committed
Rename 'new' command to 'template render'
1 parent 9c30404 commit 4780acb

File tree

6 files changed

+34
-26
lines changed

6 files changed

+34
-26
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ print("```", stdout.decode().strip(), "```", sep="\n")
6262
```
6363
usage: zorg [-h] [-c CONFIG_FILE] [-L [FILE[:LEVEL][@FORMAT]]] [-v]
6464
[--version] [-d ZETTEL_DIR]
65-
{edit,new} ...
65+
{edit,template} ...
6666
6767
The zettel note manager of the future.
6868
@@ -92,11 +92,11 @@ options:
9292
--version show program's version number and exit
9393
9494
subcommands:
95-
{edit,new}
95+
{edit,template}
9696
edit Generate new day logs from templates and open the main
9797
day log in your system's editor. This is the default
9898
subcommand.
99-
new Render a new .zo file using a .zot template.
99+
template Commands for managing .zot templates.
100100
```
101101
<!-- [[[[[end]]]]] -->
102102

src/zorg/config.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .types import FileGroupMapType
1515

1616

17-
Command = Literal["edit", "new"]
17+
Command = Literal["edit", "render"]
1818

1919
logger = Logger(__name__)
2020

@@ -44,10 +44,10 @@ class EditConfig(Config):
4444
edit_day_log: bool = True
4545

4646

47-
class NewConfig(Config):
48-
"""Clack config for the 'new' command."""
47+
class TemplateRenderConfig(Config):
48+
"""Clack config for the 'template' command."""
4949

50-
command: Literal["new"]
50+
command: Literal["render"]
5151

5252
# ----- ARGUMENTS
5353
template: Path
@@ -104,15 +104,20 @@ def clack_parser(argv: Sequence[str]) -> dict[str, Any]:
104104
),
105105
)
106106

107-
new_parser = new_command(
108-
"new", help="Render a new .zo file using a .zot template."
107+
template_parser = new_command(
108+
"template", help="Commands for managing .zot templates."
109109
)
110-
new_parser.add_argument(
110+
new_template_command = clack.new_command_factory(template_parser)
111+
template_render_parser = new_template_command(
112+
"render", help="Render a new .zo file using a .zot template."
113+
)
114+
template_render_parser.add_argument(
111115
"template", type=Path, help="Path to the .zot template."
112116
)
113-
new_parser.add_argument(
117+
template_render_parser.add_argument(
114118
"variables",
115-
help="A list of comma-separated variable specs of the form key=value.",
119+
nargs="*",
120+
help="A list of variable specs of the form of key=value.",
116121
)
117122

118123
args = parser.parse_args(argv[1:])
@@ -137,7 +142,7 @@ def _process_zo_paths(kwargs: dict[str, Any]) -> None:
137142
def _convert_variables_to_var_map(kwargs: dict[str, Any]) -> None:
138143
if "variables" in kwargs:
139144
var_map = {}
140-
for var_spec in kwargs["variables"].split(","):
145+
for var_spec in kwargs["variables"]:
141146
k, v = var_spec.split("=")
142147
var_map[k] = v
143148
var_map = common.process_var_map(var_map)

src/zorg/runners.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import vimala
1515

1616
from . import common
17-
from .config import Config, EditConfig, NewConfig
17+
from .config import Config, EditConfig, TemplateRenderConfig
1818
from .file_groups import expand_file_group_paths
1919

2020

@@ -108,8 +108,8 @@ def _process_vim_commands(
108108

109109

110110
@runner
111-
def run_new(cfg: NewConfig) -> int:
112-
"""Runner for the 'new' command."""
111+
def run_template_render(cfg: TemplateRenderConfig) -> int:
112+
"""Runner for the 'template' command."""
113113
tmpl_manager = _ZorgTemplateManager(cfg)
114114
print(tmpl_manager.render(cfg.template, cfg.var_map))
115115
return 0

tests/__snapshots__/test_new_cmd.ambr renamed to tests/__snapshots__/test_template_cmd.ambr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# serializer version: 1
2-
# name: test_new[YAMLConfigFile]
2+
# name: test_template_render[YAMLConfigFile]
33
'''
44
# 1991-03-04.Mon
55
#

tests/test_config.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from clack import clack_envvars_set
77
from clack.types import ClackConfig
88

9-
from zorg.config import EditConfig, NewConfig, clack_parser
9+
from zorg.config import EditConfig, TemplateRenderConfig, clack_parser
1010

1111

1212
def test_defaultToEdit_whenNoCommandIsGiven() -> None:
@@ -33,6 +33,7 @@ def test_defaultToEdit_whenFileGroupNameIsFirstArg() -> None:
3333
def wrapped_clack_parser(argv: Sequence[str]) -> dict[str, Any]:
3434
"""Thin wrapper around clack_parser()."""
3535
with clack_envvars_set(
36-
"zorg", cast(list[type[ClackConfig]], [EditConfig, NewConfig])
36+
"zorg",
37+
cast(list[type[ClackConfig]], [EditConfig, TemplateRenderConfig]),
3738
):
3839
return clack_parser(argv)

tests/test_new_cmd.py renamed to tests/test_template_cmd.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Tests for the zorg project's 'new' CLI command."""
1+
"""Tests for the zorg project's 'template' CLI command."""
22

33
from __future__ import annotations
44

@@ -10,26 +10,28 @@
1010
from . import common as c
1111

1212

13-
def test_new(
13+
def test_template_render(
1414
main: c.MainType,
1515
capsys: CaptureFixture,
1616
tmp_path: Path,
1717
snapshot: Snapshot,
1818
) -> None:
19-
"""Test the 'new' subcommand."""
19+
"""Test the 'template render' subcommand."""
2020
zettel_dir = tmp_path / "org"
21-
template_path: Path = zettel_dir / "day_log_tmpl.zo"
21+
zot_basename = "day_log_tmpl.zo"
22+
template_path: Path = zettel_dir / zot_basename
2223
template_path.parent.mkdir(parents=True, exist_ok=True)
2324
test_data_template_path = Path(__file__).parent / Path(
24-
"data/day_log_tmpl.zo"
25+
f"data/{zot_basename}"
2526
)
2627
template_path.write_text(test_data_template_path.read_text())
2728

2829
argv = [
2930
"--dir",
3031
str(zettel_dir),
31-
"new",
32-
"day_log_tmpl.zo",
32+
"template",
33+
"render",
34+
zot_basename,
3335
"date=19910304",
3436
]
3537
assert main(*argv) == 0

0 commit comments

Comments
 (0)