diff --git a/src/cli.nim b/src/cli.nim index a6222662c..a816334f4 100644 --- a/src/cli.nim +++ b/src/cli.nim @@ -173,9 +173,11 @@ proc showHelp(exitCode: range[0..255] = 0) = const helpText = genHelpText() let appName = extractFilename(getAppFilename()) let usage = "Usage:\n" & - &" {appName} [global-options] [command-options]\n\n" - stdout.write usage - echo helpText + &" {appName} [global-options] [command-options]\n" + let f = if exitCode == 0: stdout else: stderr + f.writeLine usage + f.writeLine helpText + f.flushFile() quit(exitCode) proc showVersion = diff --git a/tests/test_binary.nim b/tests/test_binary.nim index 48093dd3d..07c682179 100644 --- a/tests/test_binary.nim +++ b/tests/test_binary.nim @@ -20,7 +20,7 @@ template execAndCheck(expectedExitCode: int; body: untyped) {.dirty.} = ## `body` must have the same return type as `execCmdEx`. let (outp, exitCode) = body if exitCode != expectedExitCode: - echo outp + stderr.writeLine outp fail() func conciseDiff(s: string): string = @@ -271,13 +271,12 @@ proc main = const helpStart = &"Usage:\n {binaryName} [global-options] [command-options]" const cmd = "nimble --verbose build -d:release" - stdout.write(&"Running `{cmd}`... ") - stdout.flushFile() + stderr.write(&"Running `{cmd}`... ") let (buildOutput, buildExitCode) = execCmdEx(cmd, workingDir = repoRootDir) if buildExitCode == 0: - echo "success" + stderr.writeLine "success" else: - echo "failure" + stderr.writeLine "failure" raise newException(OSError, buildOutput) suite "help as an argument":