diff --git a/znai-cli/src/main/java/org/testingisdocumenting/znai/cli/ZnaiCliApp.java b/znai-cli/src/main/java/org/testingisdocumenting/znai/cli/ZnaiCliApp.java index ee52a43fe..9381557d2 100644 --- a/znai-cli/src/main/java/org/testingisdocumenting/znai/cli/ZnaiCliApp.java +++ b/znai-cli/src/main/java/org/testingisdocumenting/znai/cli/ZnaiCliApp.java @@ -203,7 +203,7 @@ private PageModifiedTimeStrategy pageModifiedTimeStrategy() { private void createNew() { Path pathToScaffold = (config.isSourceRootSet() ? config.getSourceRoot() : - Paths.get("znai")).toAbsolutePath(); + Paths.get("guide")).toAbsolutePath(); ConsoleOutputs.out(Color.BLUE, "scaffolding new documentation: ", Color.PURPLE, pathToScaffold); @@ -212,7 +212,7 @@ private void createNew() { } private void announceMode(String name) { - ConsoleOutputs.out(Color.BLUE, "znai ", Color.YELLOW, name + " mode"); + ConsoleOutputs.out(Color.BLUE, ZnaiTitleWithMaybeOverride.title, " ", Color.YELLOW, name + " mode"); } private void reportHostPort(int port, String relativeUrl) { diff --git a/znai-cli/src/main/java/org/testingisdocumenting/znai/cli/ZnaiCliConfig.java b/znai-cli/src/main/java/org/testingisdocumenting/znai/cli/ZnaiCliConfig.java index 646bb5193..e2e7c8716 100644 --- a/znai-cli/src/main/java/org/testingisdocumenting/znai/cli/ZnaiCliConfig.java +++ b/znai-cli/src/main/java/org/testingisdocumenting/znai/cli/ZnaiCliConfig.java @@ -98,9 +98,9 @@ public enum OptionKey { EXPORT("export", "export destination directory", true, false), - PREVIEW_LEGACY("preview", "[DEPRECATED] preview mode (use 'znai preview' instead)", false, false), - SERVE_LEGACY("serve", "[DEPRECATED] server mode (use 'znai serve' instead)", false, false), - NEW_LEGACY("new", "[DEPRECATED] create new documentation (use 'znai new' instead)", false, false); + PREVIEW_LEGACY("preview", "[DEPRECATED] preview mode (use '" + ZnaiTitleWithMaybeOverride.title + " preview' instead)", false, false), + SERVE_LEGACY("serve", "[DEPRECATED] server mode (use '" + ZnaiTitleWithMaybeOverride.title + " serve' instead)", false, false), + NEW_LEGACY("new", "[DEPRECATED] create new documentation (use '" + ZnaiTitleWithMaybeOverride.title + " new' instead)", false, false); private final String key; private final String description; @@ -135,25 +135,25 @@ public boolean hasMultipleArgs() { static { Set commonOptions = EnumSet.of( - OptionKey.HELP, - OptionKey.VERSION, - OptionKey.SOURCE, - OptionKey.MARKUP_TYPE, - OptionKey.VALIDATE_EXTERNAL_LINKS, - OptionKey.ACTOR, - OptionKey.MODIFIED_TIME, - OptionKey.LOOKUP_PATHS + OptionKey.HELP, + OptionKey.VERSION, + OptionKey.SOURCE, + OptionKey.MARKUP_TYPE, + OptionKey.VALIDATE_EXTERNAL_LINKS, + OptionKey.ACTOR, + OptionKey.MODIFIED_TIME, + OptionKey.LOOKUP_PATHS, + OptionKey.SSL_JKS_PATH, + OptionKey.SSL_JKS_PASSWORD, + OptionKey.SSL_PEM_CERT_PATH, + OptionKey.SSL_PEM_KEY_PATH ); Set previewOptions = EnumSet.copyOf(commonOptions); previewOptions.addAll(EnumSet.of( - OptionKey.HOST, - OptionKey.PORT, - OptionKey.DEPLOY, - OptionKey.SSL_JKS_PATH, - OptionKey.SSL_JKS_PASSWORD, - OptionKey.SSL_PEM_CERT_PATH, - OptionKey.SSL_PEM_KEY_PATH + OptionKey.HOST, + OptionKey.PORT, + OptionKey.DEPLOY )); COMMAND_OPTIONS.put(Command.PREVIEW, previewOptions); COMMAND_OPTIONS.put(Command.SERVE, previewOptions); @@ -454,7 +454,7 @@ private void parseArgs(String[] args) { } private void printVersion() { - ConsoleOutputs.out(Color.YELLOW, "znai version: ", Color.CYAN, ZnaiVersion.getVersion(), + ConsoleOutputs.out(Color.YELLOW, "version: ", Color.CYAN, ZnaiVersion.getVersion(), Color.GREEN, " (", ZnaiVersion.getTimeStamp(), ")"); } @@ -612,13 +612,13 @@ private void showDeprecationWarning(CommandLine commandLine) { ConsoleOutputs.out(Color.YELLOW, "Warning: Using deprecated command-line format."); if (commandLine.hasOption(OptionKey.PREVIEW_LEGACY.getKey())) { - ConsoleOutputs.out(Color.YELLOW, "Please use 'znai preview' instead of 'znai --preview'"); + ConsoleOutputs.out(Color.YELLOW, "Please use 'preview' instead of '--preview'"); } else if (commandLine.hasOption(OptionKey.SERVE_LEGACY.getKey())) { - ConsoleOutputs.out(Color.YELLOW, "Please use 'znai serve' instead of 'znai --serve'"); + ConsoleOutputs.out(Color.YELLOW, "Please use 'serve' instead of '--serve'"); } else if (commandLine.hasOption(OptionKey.NEW_LEGACY.getKey())) { - ConsoleOutputs.out(Color.YELLOW, "Please use 'znai new' instead of 'znai --new'"); + ConsoleOutputs.out(Color.YELLOW, "Please use 'new' instead of '--new'"); } else if (commandLine.hasOption(OptionKey.EXPORT.getKey())) { - ConsoleOutputs.out(Color.YELLOW, "Please use 'znai export' instead of 'znai --export'"); + ConsoleOutputs.out(Color.YELLOW, "Please use 'export' instead of '--export'"); } ConsoleOutputs.out(Color.YELLOW, "The old format will be removed in future versions"); @@ -630,7 +630,7 @@ private void printHelp(Command command, Options options) { if (!isLegacyMode) { ConsoleOutputs.out(Color.CYAN, "\nUsage:"); - ConsoleOutputs.out(" znai [command] [options]\n"); + ConsoleOutputs.out(" " + ZnaiTitleWithMaybeOverride.title +" [command] [options]\n"); ConsoleOutputs.out(Color.CYAN, "Commands:"); for (Command cmd : Command.values()) { ConsoleOutputs.out(String.format(" %-10s", cmd.getName()), Color.WHITE, cmd.getDescription()); @@ -646,7 +646,7 @@ private void printHelp(Command command, Options options) { } } else { ConsoleOutputs.out(Color.CYAN, "\nFor command-specific options, use:"); - ConsoleOutputs.out(" znai [command] --help\n"); + ConsoleOutputs.out(" " + ZnaiTitleWithMaybeOverride.title + " [command] --help\n"); } } else { try { diff --git a/znai-cli/src/main/java/org/testingisdocumenting/znai/cli/ZnaiTitleWithMaybeOverride.java b/znai-cli/src/main/java/org/testingisdocumenting/znai/cli/ZnaiTitleWithMaybeOverride.java new file mode 100644 index 000000000..2a5fe4067 --- /dev/null +++ b/znai-cli/src/main/java/org/testingisdocumenting/znai/cli/ZnaiTitleWithMaybeOverride.java @@ -0,0 +1,10 @@ +package org.testingisdocumenting.znai.cli; + +public class ZnaiTitleWithMaybeOverride { + static final String title = init(); + + private static String init() { + var maybeOverride = System.getenv("ZNAI_APP_TITLE"); + return maybeOverride == null ? "znai" : maybeOverride; + } +} diff --git a/znai-cli/src/test/groovy/org/testingisdocumenting/znai/cli/ZnaiCliConfigTest.groovy b/znai-cli/src/test/groovy/org/testingisdocumenting/znai/cli/ZnaiCliConfigTest.groovy index 9181d451a..5cf0ec7f8 100644 --- a/znai-cli/src/test/groovy/org/testingisdocumenting/znai/cli/ZnaiCliConfigTest.groovy +++ b/znai-cli/src/test/groovy/org/testingisdocumenting/znai/cli/ZnaiCliConfigTest.groovy @@ -65,76 +65,89 @@ class ZnaiCliConfigTest { } @Test - void "preview command includes server and SSL options"() { + void "preview command options"() { def options = createOptionsForCommand(Command.PREVIEW, '--source=test') assertOnlyTheseOptions(options, - OptionKey.HOST, - OptionKey.PORT, - OptionKey.DEPLOY, - OptionKey.SSL_JKS_PATH, - OptionKey.SSL_JKS_PASSWORD, - OptionKey.SSL_PEM_CERT_PATH, - OptionKey.SSL_PEM_KEY_PATH, - OptionKey.SOURCE, - OptionKey.MARKUP_TYPE, - OptionKey.HELP, - OptionKey.VERSION, - OptionKey.VALIDATE_EXTERNAL_LINKS, - OptionKey.ACTOR, - OptionKey.MODIFIED_TIME, - OptionKey.LOOKUP_PATHS + OptionKey.HOST, + OptionKey.PORT, + OptionKey.DEPLOY, + OptionKey.SSL_JKS_PATH, + OptionKey.SSL_JKS_PASSWORD, + OptionKey.SSL_PEM_CERT_PATH, + OptionKey.SSL_PEM_KEY_PATH, + OptionKey.SOURCE, + OptionKey.MARKUP_TYPE, + OptionKey.HELP, + OptionKey.VERSION, + OptionKey.VALIDATE_EXTERNAL_LINKS, + OptionKey.ACTOR, + OptionKey.MODIFIED_TIME, + OptionKey.LOOKUP_PATHS ) } @Test - void "build command includes doc-id but not server options"() { + void "build command options"() { def options = createOptionsForCommand(Command.BUILD, '--source=test') assertOnlyTheseOptions(options, - OptionKey.DOC_ID, - OptionKey.DEPLOY, - OptionKey.SOURCE, - OptionKey.MARKUP_TYPE, - OptionKey.HELP, - OptionKey.VERSION, - OptionKey.VALIDATE_EXTERNAL_LINKS, - OptionKey.ACTOR, - OptionKey.MODIFIED_TIME, - OptionKey.LOOKUP_PATHS + OptionKey.DOC_ID, + OptionKey.DEPLOY, + OptionKey.SOURCE, + OptionKey.MARKUP_TYPE, + OptionKey.HELP, + OptionKey.VERSION, + OptionKey.VALIDATE_EXTERNAL_LINKS, + OptionKey.ACTOR, + OptionKey.MODIFIED_TIME, + OptionKey.LOOKUP_PATHS, + OptionKey.SSL_JKS_PATH, + OptionKey.SSL_JKS_PASSWORD, + OptionKey.SSL_PEM_CERT_PATH, + OptionKey.SSL_PEM_KEY_PATH, ) } @Test - void "export command includes export option but not server options"() { + void "export command options"() { def options = createOptionsForCommand(Command.EXPORT, '--source=test') assertOnlyTheseOptions(options, - OptionKey.EXPORT, - OptionKey.SOURCE, - OptionKey.MARKUP_TYPE, - OptionKey.HELP, - OptionKey.VERSION, - OptionKey.VALIDATE_EXTERNAL_LINKS, - OptionKey.ACTOR, - OptionKey.MODIFIED_TIME, - OptionKey.LOOKUP_PATHS + OptionKey.EXPORT, + OptionKey.SOURCE, + OptionKey.MARKUP_TYPE, + OptionKey.HELP, + OptionKey.VERSION, + OptionKey.VALIDATE_EXTERNAL_LINKS, + OptionKey.ACTOR, + OptionKey.MODIFIED_TIME, + OptionKey.LOOKUP_PATHS, + OptionKey.SSL_JKS_PATH, + OptionKey.SSL_JKS_PASSWORD, + OptionKey.SSL_PEM_CERT_PATH, + OptionKey.SSL_PEM_KEY_PATH, ) } @Test - void "new command shows only common options"() { + void "new command options"() { def options = createOptionsForCommand(Command.NEW, '--source=test') assertOnlyTheseOptions(options, - OptionKey.SOURCE, - OptionKey.MARKUP_TYPE, - OptionKey.HELP, - OptionKey.VERSION, - OptionKey.VALIDATE_EXTERNAL_LINKS, - OptionKey.ACTOR, - OptionKey.MODIFIED_TIME, - OptionKey.LOOKUP_PATHS + OptionKey.SOURCE, + OptionKey.MARKUP_TYPE, + OptionKey.HELP, + OptionKey.VERSION, + OptionKey.VALIDATE_EXTERNAL_LINKS, + OptionKey.ACTOR, + OptionKey.MODIFIED_TIME, + OptionKey.LOOKUP_PATHS, + OptionKey.SSL_JKS_PATH, + OptionKey.SSL_JKS_PASSWORD, + OptionKey.SSL_PEM_CERT_PATH, + OptionKey.SSL_PEM_KEY_PATH, + ) } diff --git a/znai-docs/znai/release-notes/1.81/add-2025-10-19-cli-title-override.md b/znai-docs/znai/release-notes/1.81/add-2025-10-19-cli-title-override.md new file mode 100644 index 000000000..c83619710 --- /dev/null +++ b/znai-docs/znai/release-notes/1.81/add-2025-10-19-cli-title-override.md @@ -0,0 +1 @@ +* Add: `ZNAI_APP_TITLE` to override cli output with custom tool title \ No newline at end of file diff --git a/znai-tests/src/test/groovy/docgen/ScaffoldUtils.groovy b/znai-tests/src/test/groovy/docgen/ScaffoldUtils.groovy index 3f6a740b3..64ce4c93d 100644 --- a/znai-tests/src/test/groovy/docgen/ScaffoldUtils.groovy +++ b/znai-tests/src/test/groovy/docgen/ScaffoldUtils.groovy @@ -28,7 +28,7 @@ class ScaffoldUtils { def znaiDeployRoot = tempPath.resolve('deploy-root') CliCommands.znai.run("--doc-id my-product --deploy $znaiDeployRoot", - cli.workingDir(tempPath.resolve('znai'))) + cli.workingDir(tempPath.resolve('guide'))) return server.serve(serverId, znaiDeployRoot) } diff --git a/znai-tests/src/test/groovy/scenarios/installationCheck.groovy b/znai-tests/src/test/groovy/scenarios/installationCheck.groovy index 0aec53a95..7cb511f5d 100644 --- a/znai-tests/src/test/groovy/scenarios/installationCheck.groovy +++ b/znai-tests/src/test/groovy/scenarios/installationCheck.groovy @@ -33,9 +33,9 @@ scenario('shows help') { scenario('scaffolds new documentation') { def scaffoldDir = fs.tempDir('znai-scaffold') - znai.run('--new', cli.workingDir(scaffoldDir)) + znai.run('new', cli.workingDir(scaffoldDir)) - def docRoot = scaffoldDir.resolve('znai') + def docRoot = scaffoldDir.resolve('guide') fs.textContent(docRoot.resolve('toc')).should contain('chapter-one\n' + ' getting-started') @@ -45,7 +45,7 @@ scenario('scaffolds new documentation') { scenario('preview znai docs') { String docsRoot = scaffoldedDocRoot.get() - def znaiPreview = znai.runInBackground("--preview", cli.workingDir(docsRoot)) + def znaiPreview = znai.runInBackground("preview", cli.workingDir(docsRoot)) znaiPreview.output.waitTo contain(":3333") browser.open("http://localhost:3333/preview") diff --git a/znai-tests/src/test/groovy/scenarios/preview.groovy b/znai-tests/src/test/groovy/scenarios/preview.groovy index fb7af8ac3..4450fcf1a 100644 --- a/znai-tests/src/test/groovy/scenarios/preview.groovy +++ b/znai-tests/src/test/groovy/scenarios/preview.groovy @@ -27,13 +27,13 @@ def scaffoldedPathCache = cache.value('scaffolded-docs-for-preview') scenario('scaffold docs and run preview') { def tempPath = fs.tempDir('znai-scaffold-for-preview') - CliCommands.znai.run('--new', cli.workingDir(tempPath)) + CliCommands.znai.run('new', cli.workingDir(tempPath)) - def docsPath = tempPath.resolve("znai") + def docsPath = tempPath.resolve("guide") scaffoldedPathCache.set(docsPath.toString()) def port = 3457 - def preview = CliCommands.znai.runInBackground("--preview --port=${port}", cli.workingDir(docsPath)) + def preview = CliCommands.znai.runInBackground("preview --port=${port}", cli.workingDir(docsPath)) preview.output.waitTo(contain("server started"), 30_000)