* Set default method (GET or POST)

* Allow setting variables on the commandline
This commit is contained in:
Andreas Schneider 2015-10-08 11:33:07 +02:00
parent e576805e84
commit 8e820eb2f3
2 changed files with 30 additions and 13 deletions

View File

@ -295,17 +295,25 @@ begin
AName := Copy(AName, 2, Length(AName));
if mode = pmNormal then
//Check if the variable has been set on the commandline; we do not
//have to ask the user then.
if HasOption('var:' + AName) then
begin
default := FSessionIni.ReadString(FTemplateName, AName, '');
value := Prompt(AName, default);
value := GetOptionValue('var:' + AName);
end else
begin
value := Prompt(AName, mode);
end;
if mode = pmNormal then
begin
default := FSessionIni.ReadString(FTemplateName, AName, '');
value := Prompt(AName, default);
end else
begin
value := Prompt(AName, mode);
end;
if value = '' then
Halt(3); //Cancelled
if value = '' then
Halt(3); //Cancelled
end;
FParser.Fields.Add(AName, value);
@ -416,17 +424,24 @@ end;
procedure TRestemplateApplication.ProcessCall(AURL: String);
var
s: String;
s, httpMethod: String;
request, response: TStream;
jsonParser: TJSONParser;
jsonData: TJSONData;
contentType: TContentType;
xmlDoc: TXMLDocument;
begin
httpMethod := Trim(FMethod);
if httpMethod = '' then
if (FContent.Count > 0) or (FFormFields.Count > 0) then
httpMethod := 'POST'
else
httpMethod := 'GET';
FParser.Content := AURL;
FParser.Replace;
AURL := FParser.Content;
writeln('Calling ', AURL);
writeln(httpMethod, ' ', AURL);
response := TMemoryStream.Create;
request := nil;
@ -456,10 +471,10 @@ begin
FHttp.Request := FRequest;
FHttp.HTTPOptions := FHttp.HTTPOptions + [hoNoProtocolErrorException];
if SameText('POST', FMethod) and (FFormFields.Count > 0) then
if SameText('POST', httpMethod) and (FFormFields.Count > 0) then
FHttp.Post(AURL, FFormFields, response)
else
FHttp.Perform(FMethod, AURL, request, response);
FHttp.Perform(httpMethod, AURL, request, response);
except
on E: Exception do
begin
@ -526,6 +541,8 @@ begin
Writeln('Options:');
Writeln(' -l --list');
Writeln(' Print a list of known templates.');
Writeln(' --var:<variableName>=<value>');
Writeln(' Sets the variable <variableName> to <value>.');
Writeln(' -h --help');
Writeln(' Print this help screen.');
end;

View File

@ -19,8 +19,8 @@
<VersionInfo>
<UseVersionInfo Value="True"/>
<MinorVersionNr Value="6"/>
<RevisionNr Value="1"/>
<StringTable LegalCopyright="Andreas Schneider" ProductName="restemplate" ProductVersion="0.6.1"/>
<RevisionNr Value="2"/>
<StringTable LegalCopyright="Andreas Schneider" ProductName="restemplate" ProductVersion="0.6.2"/>
</VersionInfo>
<MacroValues Count="1">
<Macro1 Name="LCLWidgetType" Value="nogui"/>