Added some methods to the command line reader for gir2pascal to assign tags to command line parameters.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2496 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
drewski207
2012-08-27 00:55:22 +00:00
parent daa7d2edf2
commit e4dbeca47f
2 changed files with 51 additions and 1 deletions

View File

@ -46,9 +46,16 @@ type
// read from commandline
procedure ReadOptions;
// string based
function HasOption(AName: String): Boolean;
function OptionValue(AName:String): String;
function OptionValues(AName: String): TStrings;
// tag based
function HasOption(AIdentifier: Integer): Boolean;
function OptionValue(AIdentifier: Integer): String;
function OptionValues(AIdentifier: Integer): TStrings;
constructor Create;
destructor Destroy; override;
function PrintHelp(MaxLineWidth: Integer): TStrings; virtual;
@ -287,6 +294,44 @@ begin
Result.Add(S);
end;
function TCommandLineOptions.HasOption(AIdentifier: Integer): Boolean;
var
Opt: TOption;
begin
Result := False;
Opt := FindOptionByIdentifier(AIdentifier);
if Opt = nil then
Exit;
Result := Opt.Present;
end;
function TCommandLineOptions.OptionValue(AIdentifier: Integer): String;
var
Opt: TOption;
begin
Result := '';
Opt := FindOptionByIdentifier(AIdentifier);
if Opt = nil then
Exit;
Result := Opt.Value;
end;
function TCommandLineOptions.OptionValues(AIdentifier: Integer): TStrings;
var
Opt: TOption;
Tmp: String;
begin
Result := TStringList.Create;
Opt := FindOptionByIdentifier(AIdentifier);
if Opt = nil then
Exit;
for Tmp in Opt.Values do
Result.Add(Tmp);
end;
constructor TCommandLineOptions.Create;
begin
FOptions := TObjectList.create(True);

View File

@ -323,7 +323,12 @@ begin
ConsoleWidth:=w.ws_col;
{$ENDIF}
Writeln('Usage: ',ExtractFileName(ParamStr(0)),' [options] -i filename');
WriteLn(FCmdOptions.PrintHelp(ConsoleWidth).Text);
with FCmdOptions.PrintHelp(ConsoleWidth) do
begin
WriteLn(Text);
Free;
end;
{
Writeln('');
writeln(' Usage: ',ExtractFileName(ParamStr(0)),' [options] -i filename');