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:
|
||||
cm().require_config()
|
||||
chdir_to_wiki()
|
||||
if cm().commit_require_branch:
|
||||
current_branch = git.read("rev-parse", "--abbrev-ref", "HEAD")
|
||||
if current_branch != cm().commit_require_branch:
|
||||
@ -99,6 +101,8 @@ class ListenCommand(CliCommand):
|
||||
)
|
||||
|
||||
def execute(self, args: argparse.Namespace) -> None:
|
||||
cm().require_config()
|
||||
chdir_to_wiki()
|
||||
try:
|
||||
tw.exec(
|
||||
[
|
||||
@ -198,6 +202,8 @@ class BuildCommand(CliCommand):
|
||||
f"in your config file.")
|
||||
|
||||
def execute(self, args: argparse.Namespace) -> None:
|
||||
cm().require_config()
|
||||
chdir_to_wiki()
|
||||
self._precheck(args.product)
|
||||
|
||||
# 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.")
|
||||
|
||||
|
||||
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)
|
||||
|
||||
# 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":
|
||||
def chdir_to_wiki():
|
||||
"""
|
||||
For most operations, we want the current directory to be the wiki folder.
|
||||
"""
|
||||
if not cm().wiki_folder:
|
||||
fail("No 'wiki_folder' option found in config. Set this option to the name "
|
||||
"of the wiki subfolder within the current directory.")
|
||||
@ -278,6 +270,22 @@ def launch():
|
||||
f"Please check that your wiki is initialized "
|
||||
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)
|
||||
|
||||
|
||||
|
@ -26,14 +26,27 @@ class ConfigurationManager:
|
||||
del sys.path[0:1]
|
||||
break
|
||||
else:
|
||||
fail(
|
||||
f"Your TZK config file could not be found. "
|
||||
f"Please ensure there is a file called tzk_config.py "
|
||||
f"in the current directory.")
|
||||
# no config file
|
||||
self.conf_mod = None
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if self.conf_mod is None:
|
||||
return None
|
||||
else:
|
||||
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:
|
||||
"""
|
||||
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_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)
|
||||
_init_gitignore()
|
||||
_initial_commit()
|
||||
|
Loading…
Reference in New Issue
Block a user