don't require a config file for 'preflight' and 'init'
This commit is contained in:
parent
e0ce707894
commit
87046ca4c8
@ -60,6 +60,8 @@ class CommitCommand(CliCommand):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def execute(self, args: argparse.Namespace) -> None:
|
def execute(self, args: argparse.Namespace) -> None:
|
||||||
|
cm().require_config()
|
||||||
|
chdir_to_wiki()
|
||||||
if cm().commit_require_branch:
|
if cm().commit_require_branch:
|
||||||
current_branch = git.read("rev-parse", "--abbrev-ref", "HEAD")
|
current_branch = git.read("rev-parse", "--abbrev-ref", "HEAD")
|
||||||
if current_branch != cm().commit_require_branch:
|
if current_branch != cm().commit_require_branch:
|
||||||
@ -99,6 +101,8 @@ class ListenCommand(CliCommand):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def execute(self, args: argparse.Namespace) -> None:
|
def execute(self, args: argparse.Namespace) -> None:
|
||||||
|
cm().require_config()
|
||||||
|
chdir_to_wiki()
|
||||||
try:
|
try:
|
||||||
tw.exec(
|
tw.exec(
|
||||||
[
|
[
|
||||||
@ -198,6 +202,8 @@ class BuildCommand(CliCommand):
|
|||||||
f"in your config file.")
|
f"in your config file.")
|
||||||
|
|
||||||
def execute(self, args: argparse.Namespace) -> None:
|
def execute(self, args: argparse.Namespace) -> None:
|
||||||
|
cm().require_config()
|
||||||
|
chdir_to_wiki()
|
||||||
self._precheck(args.product)
|
self._precheck(args.product)
|
||||||
|
|
||||||
# Find the build steps for the product the user specified.
|
# Find the build steps for the product the user specified.
|
||||||
@ -244,24 +250,10 @@ class BuildCommand(CliCommand):
|
|||||||
print(f"tzk: Build of product '{args.product}' completed successfully.")
|
print(f"tzk: Build of product '{args.product}' completed successfully.")
|
||||||
|
|
||||||
|
|
||||||
def launch():
|
def chdir_to_wiki():
|
||||||
parser = argparse.ArgumentParser()
|
"""
|
||||||
|
For most operations, we want the current directory to be the wiki folder.
|
||||||
subparsers = parser.add_subparsers()
|
"""
|
||||||
for command in sorted(CliCommand.__subclasses__(), key=lambda i: i.__name__):
|
|
||||||
subparser = subparsers.add_parser(command.cmd, help=command.help)
|
|
||||||
subparser.set_defaults(_cls=command)
|
|
||||||
command.setup_arguments(subparser) # type: ignore
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
if not hasattr(args, '_cls'):
|
|
||||||
# no subcommand was given
|
|
||||||
parser.print_help()
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
# For all operations except 'init', we start in the wiki folder.
|
|
||||||
# (For init, we're actually *creating* the wiki folder.)
|
|
||||||
if not args._cls.cmd == "init":
|
|
||||||
if not cm().wiki_folder:
|
if not cm().wiki_folder:
|
||||||
fail("No 'wiki_folder' option found in config. Set this option to the name "
|
fail("No 'wiki_folder' option found in config. Set this option to the name "
|
||||||
"of the wiki subfolder within the current directory.")
|
"of the wiki subfolder within the current directory.")
|
||||||
@ -278,6 +270,22 @@ def launch():
|
|||||||
f"Please check that your wiki is initialized "
|
f"Please check that your wiki is initialized "
|
||||||
f"and you specified the correct wiki_folder_name.")
|
f"and you specified the correct wiki_folder_name.")
|
||||||
|
|
||||||
|
|
||||||
|
def launch():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
subparsers = parser.add_subparsers()
|
||||||
|
for command in sorted(CliCommand.__subclasses__(), key=lambda i: i.__name__):
|
||||||
|
subparser = subparsers.add_parser(command.cmd, help=command.help)
|
||||||
|
subparser.set_defaults(_cls=command)
|
||||||
|
command.setup_arguments(subparser) # type: ignore
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
if not hasattr(args, '_cls'):
|
||||||
|
# no subcommand was given
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
args._cls().execute(args)
|
args._cls().execute(args)
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,14 +26,27 @@ class ConfigurationManager:
|
|||||||
del sys.path[0:1]
|
del sys.path[0:1]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
fail(
|
# no config file
|
||||||
f"Your TZK config file could not be found. "
|
self.conf_mod = None
|
||||||
f"Please ensure there is a file called tzk_config.py "
|
|
||||||
f"in the current directory.")
|
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
|
if self.conf_mod is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
return getattr(self.conf_mod, attr, None)
|
return getattr(self.conf_mod, attr, None)
|
||||||
|
|
||||||
|
def has_config(self) -> bool:
|
||||||
|
return self.conf_mod is not None
|
||||||
|
|
||||||
|
def require_config(self) -> None:
|
||||||
|
"""
|
||||||
|
Quit with exit status 1 if no config file was found.
|
||||||
|
"""
|
||||||
|
if not self.has_config():
|
||||||
|
fail(f"No tzk_config.py found in the current directory. "
|
||||||
|
f"(Try 'tzk init' if you want to create a new one.)")
|
||||||
|
|
||||||
|
#TODO: trash this function
|
||||||
def write_attr(self, attr: str, value: str) -> bool:
|
def write_attr(self, attr: str, value: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Try to add a simple attribute = string value config parameter to the
|
Try to add a simple attribute = string value config parameter to the
|
||||||
|
@ -166,7 +166,7 @@ def install(wiki_name: str, tw_version_spec: str, author: Optional[str]):
|
|||||||
|
|
||||||
_init_npm(wiki_name, tw_version_spec, author)
|
_init_npm(wiki_name, tw_version_spec, author)
|
||||||
_init_tw(wiki_name)
|
_init_tw(wiki_name)
|
||||||
warnings |= not _save_wikifolder_to_config(wiki_name)
|
#warnings |= not _save_wikifolder_to_config(wiki_name) ## TODO: now write entire config
|
||||||
_add_filesystem_plugins(wiki_name)
|
_add_filesystem_plugins(wiki_name)
|
||||||
_init_gitignore()
|
_init_gitignore()
|
||||||
_initial_commit()
|
_initial_commit()
|
||||||
|
Loading…
Reference in New Issue
Block a user