diff --git a/README.md b/README.md index 72f9640..dd55b26 100644 --- a/README.md +++ b/README.md @@ -129,18 +129,17 @@ The `-h` argument above will print the list of available arguments: usage: __main__.py [--copy_assets] [--content CONTENT] [--output OUTPUT] [-h] options: - --copy_assets (bool, default=False) Copy assets instead of symlinking to them - --content CONTENT - (str, default=test_content) Directory to read the input content from. - --output OUTPUT - (str, default=test_output) Directory to send the output. WARNING: This will be deleted first. - -h, --help show this help message and exit + --content CONTENT (str, required) Directory to read the input content from. + --output OUTPUT (str, required) Directory to send the output to. WARNING: This will be deleted. + --clear_output_dir (bool, default=False) Delete the output directory, if it already exists. + --copy_assets (bool, default=False) Copy static assets instead of symlinking to them. + -h, --help show this help message and exit ``` As might be obvious above, you set the `content` to your content directory. The output directory will be deleted entirely, before being written to. To test against `test_content` (and generate output to `test_output`), run it like this: ```sh -python -m alteza --content test_content --output test_output +python -m alteza --content test_content --output test_output --clear_output_dir ``` #### Code Style @@ -163,7 +162,7 @@ pytype alteza # should have zero errors too Or, all at once with: `mypy alteza ; pyflakes alteza ; pyre check ; pyright alteza ; pytype alteza`. Pytype is pretty slow, so feel free to omit it. #### Linting -Linting policy is very strict. [Pylint](https://pylint.pycqa.org/en/latest/index.html) must issue a perfect 10/10 score, otherwise the [Pylint CI check](https://github.com/arjun-menon/alteza/actions/workflows/pylint.yml) will fail. +Linting policy is very strict. [Pylint](https://pylint.pycqa.org/en/latest/index.html) must issue a perfect 10/10 score, otherwise the Pylint CI check will fail. On a side note, you can see **a UML diagram** of the Alteza code if you click on any one of the completed workflow runs for the [Pylint CI check](https://github.com/arjun-menon/alteza/actions/workflows/pylint.yml). To test whether lints are passing, simply run: ``` diff --git a/alteza/engine.py b/alteza/engine.py index 211d344..2d3dffb 100644 --- a/alteza/engine.py +++ b/alteza/engine.py @@ -29,10 +29,8 @@ class Args(Tap): # pyre-ignore[13] content: str # Directory to read the input content from. output: str # Directory to send the output to. WARNING: This will be deleted. - reset_output_dir: bool = ( - False # Delete the output directory, if it already exists. (TODO) - ) - copy_assets: bool = False # Copy assets instead of symlinking to them + clear_output_dir: bool = False # Delete the output directory, if it already exists. + copy_assets: bool = False # Copy static assets instead of symlinking to them. seed: str = "{}" # seed data to add to the initial/root env (TODO!) @@ -307,13 +305,19 @@ def _linkStaticAsset(fileNode: FileNode, shouldCopy: bool) -> None: os.symlink(fileNode.absoluteFilePath, fileNode.fileName) @staticmethod - def _resetOutputDir(outputDir: str) -> None: + def _resetOutputDir(outputDir: str, shouldDelete: bool) -> None: if os.path.isfile(outputDir): raise AltezaException( f"A file named {outputDir} already exists. Please move it or delete it. " "Note that if this had been a directory, we would have erased it." ) if os.path.isdir(outputDir): + if not shouldDelete: + raise AltezaException( + "Specified output directory '%s' already exists." + "Please use --clear_output_dir to delete it prior to site generation." + % outputDir + ) print( f"Deleting directory {Fore.dark_red_2}%s{Style.reset} and all of its content...\n" % outputDir @@ -336,7 +340,7 @@ def walk(curDir: DirNode) -> None: Generate._linkStaticAsset(fileNode, args.copy_assets) outputDir = args.output - Generate._resetOutputDir(outputDir) + Generate._resetOutputDir(outputDir, args.clear_output_dir) print("Generating...") with enterDir(outputDir):