diff --git a/URestemplateApp.pas b/URestemplateApp.pas index 966269a..d927e04 100644 --- a/URestemplateApp.pas +++ b/URestemplateApp.pas @@ -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:='); + Writeln(' Sets the variable to .'); Writeln(' -h --help'); Writeln(' Print this help screen.'); end; diff --git a/restemplate.lpi b/restemplate.lpi index bc6d31e..f427924 100644 --- a/restemplate.lpi +++ b/restemplate.lpi @@ -19,8 +19,8 @@ - - + +