add listen command
This commit is contained in:
parent
7da128ea80
commit
b61ff148ed
@ -3,6 +3,9 @@ import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
class ConfigurationManager:
|
||||
def __init__(self):
|
||||
config_path = Path.cwd()
|
||||
|
||||
for child in sorted(config_path.iterdir()):
|
||||
@ -10,7 +13,7 @@ for child in sorted(config_path.iterdir()):
|
||||
mod_name = child.name.rsplit('.', 1)[0]
|
||||
if mod_name == 'tzk_config':
|
||||
sys.path.insert(0, str(config_path))
|
||||
importlib.import_module(mod_name)
|
||||
self.conf_mod = importlib.import_module(mod_name)
|
||||
del sys.path[0]
|
||||
break
|
||||
else:
|
||||
@ -19,3 +22,6 @@ else:
|
||||
f"Please ensure there is a file called tzk_config.py "
|
||||
f"in the current directory.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
def __getattr__(self, attr):
|
||||
return getattr(self.conf_mod, attr, None)
|
||||
|
12
tw.py
Normal file
12
tw.py
Normal file
@ -0,0 +1,12 @@
|
||||
import subprocess
|
||||
from typing import Sequence
|
||||
|
||||
|
||||
def exec(args: Sequence[Sequence[str]]) -> None:
|
||||
bin_dir = subprocess.check_output(("npm", "bin"), text=True).strip()
|
||||
call_args = [bin_dir + "/tiddlywiki"]
|
||||
for tw_arg in args:
|
||||
call_args.append(f"--{tw_arg[0]}")
|
||||
for inner_arg in tw_arg[1:]:
|
||||
call_args.append(inner_arg)
|
||||
return subprocess.call(call_args)
|
40
tzk.py
40
tzk.py
@ -2,7 +2,9 @@ from abc import ABC, abstractmethod, abstractclassmethod
|
||||
import argparse
|
||||
import os
|
||||
|
||||
import config
|
||||
import git
|
||||
import tw
|
||||
|
||||
|
||||
class CliCommand(ABC):
|
||||
@ -40,7 +42,43 @@ class CommitCommand(CliCommand):
|
||||
git.exec("push", "backup")
|
||||
|
||||
|
||||
import config
|
||||
class ListenCommand(CliCommand):
|
||||
cmd = "listen"
|
||||
help = "Start a TiddlyWiki server in the current directory."
|
||||
|
||||
@classmethod
|
||||
def setup_arguments(self, parser: argparse.ArgumentParser) -> None:
|
||||
parser.add_argument(
|
||||
"-p", "--port",
|
||||
metavar="PORT",
|
||||
help="Port to listen on.",
|
||||
default=str(cm.listen_port or "8080"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--username",
|
||||
metavar="USERNAME",
|
||||
default=cm.listen_username or "",
|
||||
help="Username to use for basic authentication, if any.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--password",
|
||||
metavar="PASSWORD",
|
||||
default=cm.listen_password or "",
|
||||
help="Password to use for basic authentication, if any.",
|
||||
)
|
||||
|
||||
def execute(self, args: argparse.Namespace) -> None:
|
||||
tw.exec(
|
||||
[
|
||||
("listen",
|
||||
f"port={args.port}",
|
||||
f"username={args.username}",
|
||||
f"password={args.password}")
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
cm = config.ConfigurationManager()
|
||||
|
||||
os.chdir("zk-wiki")
|
||||
# TODO: confirm we're in the right directory
|
||||
|
Loading…
Reference in New Issue
Block a user