Add help to command line arguments
This commit is contained in:
parent
6e8e993aba
commit
141166392c
@ -1,6 +1,6 @@
|
||||
program downloader;
|
||||
|
||||
uses fphttpclient, base64, opensslsockets, fpjson, jsonparser, SysUtils, process, Classes, libtar, CustApp;
|
||||
uses fphttpclient, base64, opensslsockets, fpjson, jsonparser, SysUtils, process, Classes, libtar, CustApp, Math;
|
||||
|
||||
var
|
||||
gameId: Integer;
|
||||
@ -140,10 +140,55 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure displayHelp;
|
||||
const
|
||||
optionFlags: TStringArray = (
|
||||
'-h, --help',
|
||||
'-g, --gameid <game id>',
|
||||
'-u, --username <username>',
|
||||
'-p, --password <password>');
|
||||
optionDescriptions: TStringArray = (
|
||||
'Display help.',
|
||||
'Sets the game id. This is required.',
|
||||
'Sets the username for authentication.',
|
||||
'Sets the password for authentication.');
|
||||
|
||||
var
|
||||
i, lenFlag, lenDesc, maxLenFlag, maxLenDesc, minLenFlag, minLenDesc: Integer;
|
||||
|
||||
begin
|
||||
maxLenFlag := 0;
|
||||
maxLenDesc := 0;
|
||||
minLenFlag := 1000;
|
||||
minLenDesc := 1000;
|
||||
for i := 0 to Length(optionFlags)-1 do
|
||||
begin
|
||||
minLenFlag := Min(minLenFlag, Length(optionFlags[i]));
|
||||
maxLenFlag := Max(maxLenFlag, Length(optionFlags[i]));
|
||||
minLenDesc := Min(minLenDesc, Length(optionDescriptions[i]));
|
||||
maxLenDesc := Max(maxLenDesc, Length(optionDescriptions[i]));
|
||||
end;
|
||||
WriteLn('Usage: downloader.exe [options]');
|
||||
WriteLn;
|
||||
WriteLn('Options:');
|
||||
for i := 0 to Length(optionFLags)-1 do
|
||||
begin
|
||||
lenFlag := Length(optionFLags[i]);
|
||||
lenDesc := Length(optionDescriptions[i]);
|
||||
Write(optionFlags[i]:(lenFlag+2));
|
||||
WriteLn(optionDescriptions[i]:(lenDesc+maxLenFlag-lenFlag+2))
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
app := TCustomApplication.Create(nil);
|
||||
errorMsg := app.checkOptions('g:u:p:', 'gameid: username: password:');
|
||||
if (errorMsg = '') then
|
||||
errorMsg := app.checkOptions('hg:u:p:', 'help gameid: username: password:');
|
||||
if (errorMsg <> '') or app.HasOption('h', 'help') then
|
||||
begin
|
||||
WriteLn(errorMsg);
|
||||
displayHelp;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if app.HasOption('g', 'gameid') then
|
||||
begin
|
||||
@ -172,10 +217,6 @@ begin
|
||||
begin
|
||||
WriteLn('No game id was given');
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
WriteLn(errorMsg);
|
||||
end;
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user