diff --git a/CHANGELOG.md b/CHANGELOG.md index c0ceb7f..ef76c70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v1.2.0 (2025-07-11) +- added --no-server option + ## v1.2.0 (2023-08-22) ### Feat diff --git a/README.md b/README.md index c7ca480..3abc63e 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,9 @@ build the project documentation, and start the server. If there's an error in any of these steps, the tool will print an error message and return an error code. +### The `--no-server` Argument +When passed `--no-server`, starting the server is skipped. + ## Known Issues ### Missing MkDocs Plugins diff --git a/src/check_mkdocs/check_mkdocs.py b/src/check_mkdocs/check_mkdocs.py index dd97773..3456467 100644 --- a/src/check_mkdocs/check_mkdocs.py +++ b/src/check_mkdocs/check_mkdocs.py @@ -81,6 +81,8 @@ def main(argv: None = None) -> int: `serve(config_file=config_file)` function. If there is an error during the server start process, it returns a user-friendly error message. + If --no-server is passed as an argument, starting the server is skipped. + Finally, the function returns 0 if all the above processes are successful. """ parser = argparse.ArgumentParser() @@ -105,6 +107,15 @@ def main(argv: None = None) -> int: default=False, help="Flag to generate a build of the documentation in your project. Default is False.", ) + + parser.add_argument( + "--no-server", + dest="no_server", + action="store_true", + default=False, + help="Flag to skip starting the mkdocs as a server. Default is False.", + ) + parser.add_argument( "--custom-tags", dest="custom_tags", @@ -170,25 +181,28 @@ def main(argv: None = None) -> int: config_file, "Error building the documentation", e ) - print("Trying to start the server...") # Start the server - try: - server_process = subprocess.Popen( - [ - "mkdocs", - "serve", - "--config-file", - config_file, - "--no-livereload", - "--dirty", - ] - ) - time.sleep(5) # wait for 5 seconds to let the server start - print("Shutting down...") - server_process.terminate() - server_process.wait() - except Exception as e: - return _generate_user_friendly_error_message(config_file, "Error starting the server", e) + if not args.no_server: + print("Trying to start the server...") + try: + server_process = subprocess.Popen( + [ + "mkdocs", + "serve", + "--config-file", + config_file, + "--no-livereload", + "--dirty", + ] + ) + time.sleep(5) # wait for 5 seconds to let the server start + print("Shutting down...") + server_process.terminate() + server_process.wait() + except Exception as e: + return _generate_user_friendly_error_message( + config_file, "Error starting the server", e + ) return 0