Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli, tests: write more things to stderr #205

Merged
merged 3 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/cli.nim
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,22 @@ proc showHelp(exitCode: range[0..255] = 0) =
const helpText = genHelpText()
let appName = extractFilename(getAppFilename())
let usage = "Usage:\n" &
&" {appName} [global-options] <command> [command-options]\n\n"
stdout.write usage
echo helpText
&" {appName} [global-options] <command> [command-options]\n"
let f = if exitCode == 0: stdout else: stderr
f.writeLine usage
f.writeLine helpText
if f == stdout:
f.flushFile()
quit(exitCode)

proc showVersion =
echo &"{configletVersion}"
quit(0)

proc showError*(s: string) =
stdout.styledWrite(fgRed, "Error: ")
stdout.write(s)
stdout.write("\n\n")
stderr.styledWrite(fgRed, "Error: ")
stderr.write(s)
stderr.write("\n\n")
ee7 marked this conversation as resolved.
Show resolved Hide resolved
showHelp(exitCode = 1)

func formatOpt(kind: CmdLineKind, key: string, val = ""): string =
Expand Down
7 changes: 3 additions & 4 deletions tests/test_binary.nim
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,12 @@ proc main =
const helpStart = &"Usage:\n {binaryName} [global-options] <command> [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":
Expand Down