Added password entry support

This commit is contained in:
Andreas Schneider 2015-09-29 13:47:00 +02:00
parent 4babd13dc7
commit 5da2776f5d
2 changed files with 28 additions and 5 deletions

View File

@ -72,6 +72,10 @@ Once the first none-empty line is unrecognized (no command found), the parser wi
: Prompts the user for the input of `<variablename>`. If the value has been given in a previous run, it is suggested as default value so the user can simply accept the "last" value. This eases re-runs of the same profile with only minor (or no) changes.
This can be repeated multiple times.
`Ask#<variablename>`
: Prompts the user for the hidden input of `<variablename>`. This can be used to input passwords. These values are not persisted and therefore no default values are suggested.
This can be repeated multiple times.
`Header <http header>`
: Sets the given http header for the request.
This can be repeated multiple times.

View File

@ -149,10 +149,11 @@ end;
function TRestemplateApplication.ProcessCommand(ALine: String): Boolean;
begin
Result := False;
if AnsiStartsStr('Ask ', ALine) then
//The first char after "Ask" is treated as "mode". "#" means password.
if AnsiStartsStr('Ask', ALine) then
begin
Result := True;
CmdAskUser(Copy(ALine, 5, Length(ALine)));
CmdAskUser(Copy(ALine, 4, Length(ALine)));
end else
if AnsiStartsStr('Header ', ALine) then
begin
@ -191,17 +192,35 @@ end;
procedure TRestemplateApplication.CmdAskUser(AName: String);
var
mode: TPromptMode;
value, default: String;
begin
default := FSessionIni.ReadString(FTemplateName, AName, '');
value := Prompt(AName, default);
if Length(AName) < 2 then
raise Exception.Create('Asking without variable!');
if AName[1] <> ' ' then
mode := pmPassword
else
mode := pmNormal;
AName := Copy(AName, 2, Length(AName));
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
FParser.Fields.Add(AName, value);
FSessionIni.WriteString(FTemplateName, AName, value);
if mode = pmNormal then
FSessionIni.WriteString(FTemplateName, AName, value);
end;
procedure TRestemplateApplication.CmdHeader(AHeader: String);