summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKeita Haga <keitahaga@msn.com>2012-12-16 05:30:57 +0900
committerKeita Haga <keitahaga@msn.com>2012-12-16 05:30:57 +0900
commit9564e7069b2d11c8ad54a07e5676cc952c711114 (patch)
treef8d49ebd8d5e297543547cc800b20feaccc99f29
parent77492158aca520b6f5192885147953aa35e830b2 (diff)
downloadNim-9564e7069b2d11c8ad54a07e5676cc952c711114.tar.gz
Better CLI error message when options are invalid
-rwxr-xr-xcompiler/commands.nim11
1 files changed, 8 insertions, 3 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 4b9a47d37..cd12728ea 100755
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -64,8 +64,13 @@ proc writeCommandLineUsage() =
     MsgWriteln(getCommandLineDesc())
     helpWritten = true
 
+proc addPrefix(switch: string): string =
+  if len(switch) == 1: result = "-" & switch
+  else: result = "--" & switch
+
 proc InvalidCmdLineOption(pass: TCmdLinePass, switch: string, info: TLineInfo) = 
-  LocalError(info, errInvalidCmdLineOption, switch)
+  if switch == " ": LocalError(info, errInvalidCmdLineOption, "-")
+  else: LocalError(info, errInvalidCmdLineOption, addPrefix(switch))
 
 proc splitSwitch(switch: string, cmd, arg: var string, pass: TCmdLinePass, 
                  info: TLineInfo) = 
@@ -97,10 +102,10 @@ proc ProcessOnOffSwitchG(op: TGlobalOptions, arg: string, pass: TCmdlinePass,
   else: LocalError(info, errOnOrOffExpectedButXFound, arg)
   
 proc ExpectArg(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) = 
-  if arg == "": LocalError(info, errCmdLineArgExpected, switch)
+  if arg == "": LocalError(info, errCmdLineArgExpected, addPrefix(switch))
   
 proc ExpectNoArg(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) = 
-  if arg != "": LocalError(info, errCmdLineNoArgExpected, switch)
+  if arg != "": LocalError(info, errCmdLineNoArgExpected, addPrefix(switch))
   
 proc ProcessSpecificNote(arg: string, state: TSpecialWord, pass: TCmdlinePass, 
                          info: TLineInfo) =