Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow set a default value to Boolean switch #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/GpCommandLineParser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@
// example parameter configuration
// TCommandLine = class
// strict private
// FAutoTest : boolean;
// FExtraFiles: string;
// FFromDate : string;
// FImportDir : string;
// FInputFile : string;
// FNumDays : integer;
// FOutputFile: string;
// FPrecision : string;
// FToDateTime: string;
// FAutoTest : boolean;
// FExtraFiles : string;
// FFromDate : string;
// FImportDir : string;
// FInputFile : string;
// FNumDays : integer;
// FOutputFile : string;
// FPrecision : string;
// FToDateTime : string;
// FIgnoreFeatureA: Boolean;
// public
// [CLPLongName('ToDate'), CLPDescription('Set ending date/time', '<dt>')]
// property ToDateTime: string read FToDateTime write FToDateTime;
Expand Down Expand Up @@ -76,6 +77,9 @@ // TCommandLine = class
//
// [CLPPositionRest, CLPDescription('Extra files'), CLPName('extra_files')]
// property ExtraFiles: string read FExtraFiles write FExtraFiles;
//
// [CLPPositionRest, CLPDescription('Ignore feature A'), CLPName('ignore-feature-a'), CLPDefaultAttribute(DefaultTrueBoolStr)]
// property IgnoreFeatureA: Boolean read FIgnoreFeatureA write FIgnoreFeatureA;
// end;

unit GpCommandLineParser;
Expand Down Expand Up @@ -531,6 +535,7 @@ function TSwitchData.SetValue(const value: string): boolean;
iValue: integer;
prop : TRttiProperty;
typ : TRttiType;
bValue: Boolean;
begin
Result := true;
ctx := TRttiContext.Create;
Expand All @@ -540,6 +545,11 @@ function TSwitchData.SetValue(const value: string): boolean;
case SwitchType of
stString:
prop.SetValue(FInstance, value);
stBoolean:
begin
if TryStrToBool(value, bValue) then
prop.SetValue(FInstance, bValue);
end;
stInteger:
begin
Val(value, iValue, c);
Expand Down