From 469d9d02e5e52b7212507ad97f1cf1cd1e45db5c Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Sun, 9 May 2010 13:17:06 +0200 Subject: [PATCH] Fix command line args --- Projects/SAMufasaGUI/testunit.pas | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Projects/SAMufasaGUI/testunit.pas b/Projects/SAMufasaGUI/testunit.pas index 48f600d..e1f37d7 100644 --- a/Projects/SAMufasaGUI/testunit.pas +++ b/Projects/SAMufasaGUI/testunit.pas @@ -1418,21 +1418,33 @@ var ErrorMsg : string; begin DoRun := false; - if Paramcount = 1 then + // paramcount = 1 means we got only one parameter. We assume this to be a file. + // and try to open it accordingly + if (Paramcount = 1) and not (Application.HasOption('open')) then begin + writeln('Opening file: ' + ParamStr(1)); if FileExists(ParamStr(1)) then + begin LoadScriptFile(paramstr(1)); + end; end else - begin; - ErrorMsg:=Application.CheckOptions('ro:','run open:'); + // we have more parameters. Check for specific options. (-r -o, --run --open) + begin + ErrorMsg:=Application.CheckOptions('ro:',['run', 'open:']); if ErrorMsg <> '' then - mDebugLn(ErrorMSG) - else + begin + mDebugLn('ERROR IN COMMAND LINE ARGS: ' + ErrorMSG) + end else begin if Application.HasOption('o','open') then - begin; + begin + writeln('Opening file: ' + Application.GetOptionValue('o','open')); LoadScriptFile(Application.GetOptionValue('o','open')); DoRun:= Application.HasOption('r','run'); + end else + // no valid options + begin + writeln('No valid command line args are passed'); end; end; end;