* Set default method (GET or POST)
* Allow setting variables on the commandline
This commit is contained in:
parent
e576805e84
commit
8e820eb2f3
|
@ -295,17 +295,25 @@ begin
|
||||||
|
|
||||||
AName := Copy(AName, 2, Length(AName));
|
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
|
begin
|
||||||
default := FSessionIni.ReadString(FTemplateName, AName, '');
|
value := GetOptionValue('var:' + AName);
|
||||||
value := Prompt(AName, default);
|
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
value := Prompt(AName, mode);
|
if mode = pmNormal then
|
||||||
end;
|
begin
|
||||||
|
default := FSessionIni.ReadString(FTemplateName, AName, '');
|
||||||
|
value := Prompt(AName, default);
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
value := Prompt(AName, mode);
|
||||||
|
end;
|
||||||
|
|
||||||
if value = '' then
|
if value = '' then
|
||||||
Halt(3); //Cancelled
|
Halt(3); //Cancelled
|
||||||
|
end;
|
||||||
|
|
||||||
FParser.Fields.Add(AName, value);
|
FParser.Fields.Add(AName, value);
|
||||||
|
|
||||||
|
@ -416,17 +424,24 @@ end;
|
||||||
|
|
||||||
procedure TRestemplateApplication.ProcessCall(AURL: String);
|
procedure TRestemplateApplication.ProcessCall(AURL: String);
|
||||||
var
|
var
|
||||||
s: String;
|
s, httpMethod: String;
|
||||||
request, response: TStream;
|
request, response: TStream;
|
||||||
jsonParser: TJSONParser;
|
jsonParser: TJSONParser;
|
||||||
jsonData: TJSONData;
|
jsonData: TJSONData;
|
||||||
contentType: TContentType;
|
contentType: TContentType;
|
||||||
xmlDoc: TXMLDocument;
|
xmlDoc: TXMLDocument;
|
||||||
begin
|
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.Content := AURL;
|
||||||
FParser.Replace;
|
FParser.Replace;
|
||||||
AURL := FParser.Content;
|
AURL := FParser.Content;
|
||||||
writeln('Calling ', AURL);
|
writeln(httpMethod, ' ', AURL);
|
||||||
|
|
||||||
response := TMemoryStream.Create;
|
response := TMemoryStream.Create;
|
||||||
request := nil;
|
request := nil;
|
||||||
|
@ -456,10 +471,10 @@ begin
|
||||||
FHttp.Request := FRequest;
|
FHttp.Request := FRequest;
|
||||||
FHttp.HTTPOptions := FHttp.HTTPOptions + [hoNoProtocolErrorException];
|
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)
|
FHttp.Post(AURL, FFormFields, response)
|
||||||
else
|
else
|
||||||
FHttp.Perform(FMethod, AURL, request, response);
|
FHttp.Perform(httpMethod, AURL, request, response);
|
||||||
except
|
except
|
||||||
on E: Exception do
|
on E: Exception do
|
||||||
begin
|
begin
|
||||||
|
@ -526,6 +541,8 @@ begin
|
||||||
Writeln('Options:');
|
Writeln('Options:');
|
||||||
Writeln(' -l --list');
|
Writeln(' -l --list');
|
||||||
Writeln(' Print a list of known templates.');
|
Writeln(' Print a list of known templates.');
|
||||||
|
Writeln(' --var:<variableName>=<value>');
|
||||||
|
Writeln(' Sets the variable <variableName> to <value>.');
|
||||||
Writeln(' -h --help');
|
Writeln(' -h --help');
|
||||||
Writeln(' Print this help screen.');
|
Writeln(' Print this help screen.');
|
||||||
end;
|
end;
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
<VersionInfo>
|
<VersionInfo>
|
||||||
<UseVersionInfo Value="True"/>
|
<UseVersionInfo Value="True"/>
|
||||||
<MinorVersionNr Value="6"/>
|
<MinorVersionNr Value="6"/>
|
||||||
<RevisionNr Value="1"/>
|
<RevisionNr Value="2"/>
|
||||||
<StringTable LegalCopyright="Andreas Schneider" ProductName="restemplate" ProductVersion="0.6.1"/>
|
<StringTable LegalCopyright="Andreas Schneider" ProductName="restemplate" ProductVersion="0.6.2"/>
|
||||||
</VersionInfo>
|
</VersionInfo>
|
||||||
<MacroValues Count="1">
|
<MacroValues Count="1">
|
||||||
<Macro1 Name="LCLWidgetType" Value="nogui"/>
|
<Macro1 Name="LCLWidgetType" Value="nogui"/>
|
||||||
|
|
Loading…
Reference in New Issue