diff --git a/confutils.nim b/confutils.nim index 8b65a87..421d30c 100644 --- a/confutils.nim +++ b/confutils.nim @@ -121,10 +121,16 @@ when useBufferedOutput: else: template errorOutput(args: varargs[untyped]) = - styledWrite stderr, args + try: + styledWrite stderr, args + except IOError, ValueError: + discard template helpOutput(args: varargs[untyped]) = - styledWrite stdout, args + try: + styledWrite stdout, args + except IOError, ValueError: + discard template flushOutput = discard @@ -969,9 +975,15 @@ proc loadImpl[C, SecondarySources]( let trailing = if opt.typename != "bool": "=" else: "" if argName in filterKind and len(opt.name) > 0: - stdout.writeLine("--", opt.name, trailing) + try: + stdout.writeLine("--", opt.name, trailing) + except IOError: + discard if argAbbr in filterKind and len(opt.abbr) > 0: - stdout.writeLine('-', opt.abbr, trailing) + try: + stdout.writeLine('-', opt.abbr, trailing) + except IOError: + discard let completion = splitCompletionLine() # If we're not asked to complete a command line the result is an empty list @@ -1017,12 +1029,18 @@ proc loadImpl[C, SecondarySources]( let opt = findOpt(cmdStack, option_word) if opt != nil: for arg in getArgCompletions(opt, cur_word): - stdout.writeLine(arg) + try: + stdout.writeLine(arg) + except IOError: + discard elif cmdStack[^1].hasSubCommands: # Show all the available subcommands for subCmd in subCmds(cmdStack[^1]): if startsWithIgnoreStyle(subCmd.name, cur_word): - stdout.writeLine(subCmd.name) + try: + stdout.writeLine(subCmd.name) + except IOError: + discard else: # Full options listing for i in countdown(cmdStack.len - 1, 0): @@ -1234,4 +1252,3 @@ func load*(f: TypedInputFile): f.ContentType = else: mixin loadFile loadFile(f.Format, f.string, f.ContentType) -