diff --git a/URestemplateApp.pas b/URestemplateApp.pas index 484146d..62bf3bf 100644 --- a/URestemplateApp.pas +++ b/URestemplateApp.pas @@ -54,7 +54,8 @@ type procedure CmdHighlight(AData: String); procedure ProcessCall(AURL: String); //Helper - procedure ListProfiles; + procedure WriteHelp; + procedure ListTemplates; procedure WriteContent; public constructor Create; overload; @@ -64,7 +65,7 @@ type implementation uses - strutils, crt, UCRTHelper, fpjson, DOM, XMLRead, XMLWrite; + strutils, crt, UCRTHelper, fpjson, DOM, XMLRead, XMLWrite, vinfo; type TContentType = (ctOther, ctJSON, ctXML); @@ -90,17 +91,24 @@ var data: TextFile; commandMode: Boolean; begin - templateFile := FTemplateDir + ParamStr(1) + '.rest'; - - if ParamCount <> 1 then + if HasOption('l', 'list') then begin - Writeln('Usage: ', ExtractFileName(ParamStr(0)), ' '); - Writeln; - ListProfiles; - Halt(0); + ListTemplates; + Terminate; + Exit; end; - if FileExists(ParamStr(1)) then + if HasOption('h', 'help') or (ParamCount < 1) or + (ParamStr(ParamCount)[1] = '-') then + begin + WriteHelp; + Terminate; + Exit; + end; + + templateFile := FTemplateDir + ParamStr(ParamCount) + '.rest'; + + if FileExists(ParamStr(ParamCount)) then begin AssignFile(data, ParamStr(1)); FTemplateName := ExtractFileName(ParamStr(1)); @@ -110,11 +118,12 @@ begin if FileExists(templateFile) then begin AssignFile(data, templateFile); - FTemplateName := ParamStr(1); + FTemplateName := ParamStr(ParamCount); end else begin - writeln('Template not found!'); - Halt(1); + writeln('Template ', ParamStr(ParamCount), ' not found!'); + Terminate; + Exit; end; Reset(data); @@ -345,11 +354,30 @@ begin request.Free; end; -procedure TRestemplateApplication.ListProfiles; +procedure TRestemplateApplication.WriteHelp; +begin + NormVideo; + TextColor(Green); + Writeln('restemplate ', VersionInfo.GetProductVersionString); + Writeln('Copyright (c) ', VersionInfo.GetCopyright(False)); + NormVideo; + Writeln; + Writeln('Usage: ', ExtractFileName(ExeName), ' [options]