Skip to content

Commit c7b3075

Browse files
committed
[parameters] some improvements
1 parent f9b4b24 commit c7b3075

File tree

2 files changed

+182
-9
lines changed

2 files changed

+182
-9
lines changed

Diff for: Quick.Parameters.pas

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{ ***************************************************************************
22
3-
Copyright (c) 2016-2020 Kike Pérez
3+
Copyright (c) 2016-2021 Kike Pérez
44
55
Unit : Quick.Parameters
66
Description : Map comandline to class
77
Author : Kike Pérez
88
Version : 1.4
99
Created : 12/07/2020
10-
Modified : 29/07/2020
10+
Modified : 01/08/2021
1111
1212
This file is part of QuickLib: https://github.com/exilon/QuickLib
1313
@@ -156,6 +156,7 @@ TParam = class
156156
property IsPresent : Boolean read fIsPresent write fIsPresent;
157157
function IsSwitch : Boolean;
158158
function IsCommand : Boolean;
159+
function ValueIsSwitch : Boolean;
159160
end;
160161
private
161162
fParams : TObjectList<TParam>;
@@ -164,7 +165,7 @@ TParam = class
164165
{$IFDEF CONSOLE}
165166
fColorizeHelp: TColorizeHelp;
166167
{$ENDIF}
167-
function ExistParam(aParameter : TParam; const aParam : string) : Boolean;
168+
function ExistParam(aParameter : TParam; const aParam : string) : Boolean; overload;
168169
function GetParamName(aParameter : TParam; const aParam : string) : string;
169170
function GetParamValue(aParameter : TParam; const aParam : string) : string;
170171
function ValueType(const aProp : TRttiProperty) : TValueType;
@@ -176,7 +177,7 @@ TParam = class
176177
{$ENDIF}
177178
procedure Validate; virtual;
178179
public
179-
constructor Create; virtual;
180+
constructor Create(aAutoHelp : Boolean = True); virtual;
180181
destructor Destroy; override;
181182
property Description : string read fDescription write fDescription;
182183
{$IFDEF CONSOLE}
@@ -185,6 +186,7 @@ TParam = class
185186
{$ENDIF}
186187
function GetHelp : TStringList;
187188
property Help : Boolean read fHelp write fHelp;
189+
function ExistsParam(const aParam : string): Boolean; overload;
188190
end;
189191

190192
TServiceParameters = class(TParameters)
@@ -216,7 +218,7 @@ implementation
216218

217219
{ TParameter }
218220

219-
constructor TParameters.Create;
221+
constructor TParameters.Create(aAutoHelp : Boolean = True);
220222
begin
221223
{$IFDEF CONSOLE}
222224
fColorizeHelp := TColorizeHelp.Create;
@@ -225,7 +227,7 @@ constructor TParameters.Create;
225227
fParams := TObjectList<TParam>.Create(True);
226228
ParseParams;
227229
{$IFDEF CONSOLE}
228-
if fHelp then
230+
if (aAutoHelp) and (fHelp) then
229231
begin
230232
ShowHelp;
231233
Halt;
@@ -238,7 +240,8 @@ destructor TParameters.Destroy;
238240
begin
239241
fParams.Free;
240242
{$IFDEF CONSOLE}
241-
fColorizeHelp.Free;
243+
if Assigned(fColorizeHelp) then fColorizeHelp.Free;
244+
fColorizeHelp := nil;
242245
{$ENDIF}
243246
inherited;
244247
end;
@@ -310,6 +313,20 @@ function TParameters.CheckHelpSwitch: Boolean;
310313
end;
311314
end;
312315

316+
function TParameters.ExistsParam(const aParam : string): Boolean;
317+
var
318+
param : TParam;
319+
begin
320+
param := TParam.Create;
321+
param.Name := aParam;
322+
param.Alias := '';
323+
try
324+
Result := ExistParam(param,param.Name);
325+
finally
326+
param.Free;
327+
end;
328+
end;
329+
313330
procedure TParameters.ParseParams;
314331
var
315332
param : TParam;
@@ -360,10 +377,11 @@ procedure TParameters.ParseParams;
360377
begin
361378
found := ParamCount >= param.PrecisePosition;
362379
param.SwitchChar := ' ';
380+
if param.ValueIsSwitch then found := False;
363381
end
364382
else found := (ExistParam(param,param.Name)) or (ExistParam(param,param.Alias));
365383
value := nil;
366-
if found then
384+
if found then
367385
begin
368386
if param.IsSwitch then
369387
begin
@@ -681,6 +699,11 @@ function TParameters.TParam.IsSwitch: Boolean;
681699
Result := fParamType = TValueType.vtBoolean;
682700
end;
683701

702+
function TParameters.TParam.ValueIsSwitch: Boolean;
703+
begin
704+
Result := (fValue.StartsWith('/')) or (fValue.StartsWith('-')) or (fValue.StartsWith(fSwitchChar));
705+
end;
706+
684707
{ ParamSwitchChar }
685708

686709
constructor ParamSwitchChar.Create(const aSwitchChar: string);

Diff for: samples/delphi/QuickParameters/Parameters.dproj

+151-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<PropertyGroup>
33
<ProjectGuid>{720C5968-A995-48C1-B4EC-2DC16A29D2EF}</ProjectGuid>
4-
<ProjectVersion>19.0</ProjectVersion>
4+
<ProjectVersion>19.2</ProjectVersion>
55
<FrameworkType>None</FrameworkType>
66
<MainSource>Parameters.dpr</MainSource>
77
<Base>True</Base>
@@ -92,6 +92,7 @@
9292
<Android_NotificationIcon72>$(BDS)\bin\Artwork\Android\FM_NotificationIcon_72x72.png</Android_NotificationIcon72>
9393
<Android_NotificationIcon96>$(BDS)\bin\Artwork\Android\FM_NotificationIcon_96x96.png</Android_NotificationIcon96>
9494
<EnabledSysJars>android-support-v4.dex.jar;cloud-messaging.dex.jar;com-google-android-gms.play-services-ads-base.17.2.0.dex.jar;com-google-android-gms.play-services-ads-identifier.16.0.0.dex.jar;com-google-android-gms.play-services-ads-lite.17.2.0.dex.jar;com-google-android-gms.play-services-ads.17.2.0.dex.jar;com-google-android-gms.play-services-analytics-impl.16.0.8.dex.jar;com-google-android-gms.play-services-analytics.16.0.8.dex.jar;com-google-android-gms.play-services-base.16.0.1.dex.jar;com-google-android-gms.play-services-basement.16.2.0.dex.jar;com-google-android-gms.play-services-gass.17.2.0.dex.jar;com-google-android-gms.play-services-identity.16.0.0.dex.jar;com-google-android-gms.play-services-maps.16.1.0.dex.jar;com-google-android-gms.play-services-measurement-base.16.4.0.dex.jar;com-google-android-gms.play-services-measurement-sdk-api.16.4.0.dex.jar;com-google-android-gms.play-services-stats.16.0.1.dex.jar;com-google-android-gms.play-services-tagmanager-v4-impl.16.0.8.dex.jar;com-google-android-gms.play-services-tasks.16.0.1.dex.jar;com-google-android-gms.play-services-wallet.16.0.1.dex.jar;com-google-firebase.firebase-analytics.16.4.0.dex.jar;com-google-firebase.firebase-common.16.1.0.dex.jar;com-google-firebase.firebase-iid-interop.16.0.1.dex.jar;com-google-firebase.firebase-iid.17.1.1.dex.jar;com-google-firebase.firebase-measurement-connector.17.0.1.dex.jar;com-google-firebase.firebase-messaging.17.5.0.dex.jar;fmx.dex.jar;google-play-billing.dex.jar;google-play-licensing.dex.jar</EnabledSysJars>
95+
<Android_LauncherIcon192>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_192x192.png</Android_LauncherIcon192>
9596
</PropertyGroup>
9697
<PropertyGroup Condition="'$(Base_Android64)'!=''">
9798
<DCC_UsePackage>DBXSqliteDriver;RESTComponents;DBXInterBaseDriver;tethering;bindcompfmx;FmxTeeUI;FireDACIBDriver;fmx;dbexpress;IndyCore;dsnap;FireDACCommon;RESTBackendComponents;soapserver;bindengine;CloudService;FireDACCommonDriver;inet;bindcompdbx;IndyIPCommon;IndyIPServer;IndySystem;fmxFireDAC;FireDAC;FireDACSqliteDriver;ibmonitor;FMXTee;soaprtl;DbxCommonDriver;ibxpress;xmlrtl;soapmidas;ibxbindings;rtl;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;dbxcds;dsnapxml;dbrtl;IndyProtocols;$(DCC_UsePackage)</DCC_UsePackage>
@@ -110,9 +111,11 @@
110111
<Android_NotificationIcon72>$(BDS)\bin\Artwork\Android\FM_NotificationIcon_72x72.png</Android_NotificationIcon72>
111112
<Android_NotificationIcon96>$(BDS)\bin\Artwork\Android\FM_NotificationIcon_96x96.png</Android_NotificationIcon96>
112113
<EnabledSysJars>android-support-v4.dex.jar;cloud-messaging.dex.jar;com-google-android-gms.play-services-ads-base.17.2.0.dex.jar;com-google-android-gms.play-services-ads-identifier.16.0.0.dex.jar;com-google-android-gms.play-services-ads-lite.17.2.0.dex.jar;com-google-android-gms.play-services-ads.17.2.0.dex.jar;com-google-android-gms.play-services-analytics-impl.16.0.8.dex.jar;com-google-android-gms.play-services-analytics.16.0.8.dex.jar;com-google-android-gms.play-services-base.16.0.1.dex.jar;com-google-android-gms.play-services-basement.16.2.0.dex.jar;com-google-android-gms.play-services-gass.17.2.0.dex.jar;com-google-android-gms.play-services-identity.16.0.0.dex.jar;com-google-android-gms.play-services-maps.16.1.0.dex.jar;com-google-android-gms.play-services-measurement-base.16.4.0.dex.jar;com-google-android-gms.play-services-measurement-sdk-api.16.4.0.dex.jar;com-google-android-gms.play-services-stats.16.0.1.dex.jar;com-google-android-gms.play-services-tagmanager-v4-impl.16.0.8.dex.jar;com-google-android-gms.play-services-tasks.16.0.1.dex.jar;com-google-android-gms.play-services-wallet.16.0.1.dex.jar;com-google-firebase.firebase-analytics.16.4.0.dex.jar;com-google-firebase.firebase-common.16.1.0.dex.jar;com-google-firebase.firebase-iid-interop.16.0.1.dex.jar;com-google-firebase.firebase-iid.17.1.1.dex.jar;com-google-firebase.firebase-measurement-connector.17.0.1.dex.jar;com-google-firebase.firebase-messaging.17.5.0.dex.jar;fmx.dex.jar;google-play-billing.dex.jar;google-play-licensing.dex.jar</EnabledSysJars>
114+
<Android_LauncherIcon192>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_192x192.png</Android_LauncherIcon192>
113115
</PropertyGroup>
114116
<PropertyGroup Condition="'$(Base_iOSDevice64)'!=''">
115117
<DCC_UsePackage>DBXSqliteDriver;RESTComponents;DBXInterBaseDriver;tethering;bindcompfmx;FmxTeeUI;FireDACIBDriver;fmx;dbexpress;IndyCore;dsnap;FireDACCommon;RESTBackendComponents;soapserver;bindengine;CloudService;FireDACCommonDriver;inet;bindcompdbx;IndyIPCommon;IndyIPServer;IndySystem;fmxFireDAC;FireDAC;FireDACSqliteDriver;ibmonitor;FMXTee;soaprtl;DbxCommonDriver;ibxpress;xmlrtl;soapmidas;ibxbindings;rtl;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;dbxcds;dsnapxml;dbrtl;IndyProtocols;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
118+
<iOS_AppStore1024>$(BDS)\bin\Artwork\iOS\iPhone\FM_ApplicationIcon_1024x1024.png</iOS_AppStore1024>
116119
</PropertyGroup>
117120
<PropertyGroup Condition="'$(Base_iOSSimulator)'!=''">
118121
<DCC_UsePackage>DBXSqliteDriver;RESTComponents;DBXInterBaseDriver;tethering;bindcompfmx;FmxTeeUI;FireDACIBDriver;fmx;dbexpress;IndyCore;dsnap;FireDACCommon;RESTBackendComponents;soapserver;bindengine;CloudService;FireDACCommonDriver;inet;bindcompdbx;IndyIPCommon;IndyIPServer;IndySystem;fmxFireDAC;FireDAC;FireDACSqliteDriver;ibmonitor;FMXTee;soaprtl;DbxCommonDriver;ibxpress;xmlrtl;soapmidas;ibxbindings;rtl;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;dbxcds;dsnapxml;dbrtl;IndyProtocols;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
@@ -351,6 +354,16 @@
351354
<Operation>1</Operation>
352355
</Platform>
353356
</DeployClass>
357+
<DeployClass Name="Android_LauncherIcon192">
358+
<Platform Name="Android">
359+
<RemoteDir>res\drawable-xxxhdpi</RemoteDir>
360+
<Operation>1</Operation>
361+
</Platform>
362+
<Platform Name="Android64">
363+
<RemoteDir>res\drawable-xxxhdpi</RemoteDir>
364+
<Operation>1</Operation>
365+
</Platform>
366+
</DeployClass>
354367
<DeployClass Name="Android_LauncherIcon36">
355368
<Platform Name="Android">
356369
<RemoteDir>res\drawable-ldpi</RemoteDir>
@@ -602,6 +615,32 @@
602615
<Operation>0</Operation>
603616
</Platform>
604617
</DeployClass>
618+
<DeployClass Name="iOS_AppStore1024">
619+
<Platform Name="iOSDevice64">
620+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
621+
<Operation>1</Operation>
622+
</Platform>
623+
</DeployClass>
624+
<DeployClass Name="iPad_AppIcon152">
625+
<Platform Name="iOSDevice64">
626+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
627+
<Operation>1</Operation>
628+
</Platform>
629+
<Platform Name="iOSSimulator">
630+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
631+
<Operation>1</Operation>
632+
</Platform>
633+
</DeployClass>
634+
<DeployClass Name="iPad_AppIcon167">
635+
<Platform Name="iOSDevice64">
636+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
637+
<Operation>1</Operation>
638+
</Platform>
639+
<Platform Name="iOSSimulator">
640+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
641+
<Operation>1</Operation>
642+
</Platform>
643+
</DeployClass>
605644
<DeployClass Name="iPad_Launch1024x768">
606645
<Platform Name="iOSDevice32">
607646
<Operation>1</Operation>
@@ -732,6 +771,56 @@
732771
<Operation>1</Operation>
733772
</Platform>
734773
</DeployClass>
774+
<DeployClass Name="iPad_Notification40">
775+
<Platform Name="iOSDevice64">
776+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
777+
<Operation>1</Operation>
778+
</Platform>
779+
<Platform Name="iOSSimulator">
780+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
781+
<Operation>1</Operation>
782+
</Platform>
783+
</DeployClass>
784+
<DeployClass Name="iPad_Setting58">
785+
<Platform Name="iOSDevice64">
786+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
787+
<Operation>1</Operation>
788+
</Platform>
789+
<Platform Name="iOSSimulator">
790+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
791+
<Operation>1</Operation>
792+
</Platform>
793+
</DeployClass>
794+
<DeployClass Name="iPad_SpotLight80">
795+
<Platform Name="iOSDevice64">
796+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
797+
<Operation>1</Operation>
798+
</Platform>
799+
<Platform Name="iOSSimulator">
800+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
801+
<Operation>1</Operation>
802+
</Platform>
803+
</DeployClass>
804+
<DeployClass Name="iPhone_AppIcon120">
805+
<Platform Name="iOSDevice64">
806+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
807+
<Operation>1</Operation>
808+
</Platform>
809+
<Platform Name="iOSSimulator">
810+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
811+
<Operation>1</Operation>
812+
</Platform>
813+
</DeployClass>
814+
<DeployClass Name="iPhone_AppIcon180">
815+
<Platform Name="iOSDevice64">
816+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
817+
<Operation>1</Operation>
818+
</Platform>
819+
<Platform Name="iOSSimulator">
820+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
821+
<Operation>1</Operation>
822+
</Platform>
823+
</DeployClass>
735824
<DeployClass Name="iPhone_Launch1125">
736825
<Platform Name="iOSDevice32">
737826
<Operation>1</Operation>
@@ -926,6 +1015,66 @@
9261015
<Operation>1</Operation>
9271016
</Platform>
9281017
</DeployClass>
1018+
<DeployClass Name="iPhone_Notification40">
1019+
<Platform Name="iOSDevice64">
1020+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1021+
<Operation>1</Operation>
1022+
</Platform>
1023+
<Platform Name="iOSSimulator">
1024+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1025+
<Operation>1</Operation>
1026+
</Platform>
1027+
</DeployClass>
1028+
<DeployClass Name="iPhone_Notification60">
1029+
<Platform Name="iOSDevice64">
1030+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1031+
<Operation>1</Operation>
1032+
</Platform>
1033+
<Platform Name="iOSSimulator">
1034+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1035+
<Operation>1</Operation>
1036+
</Platform>
1037+
</DeployClass>
1038+
<DeployClass Name="iPhone_Setting58">
1039+
<Platform Name="iOSDevice64">
1040+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1041+
<Operation>1</Operation>
1042+
</Platform>
1043+
<Platform Name="iOSSimulator">
1044+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1045+
<Operation>1</Operation>
1046+
</Platform>
1047+
</DeployClass>
1048+
<DeployClass Name="iPhone_Setting87">
1049+
<Platform Name="iOSDevice64">
1050+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1051+
<Operation>1</Operation>
1052+
</Platform>
1053+
<Platform Name="iOSSimulator">
1054+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1055+
<Operation>1</Operation>
1056+
</Platform>
1057+
</DeployClass>
1058+
<DeployClass Name="iPhone_Spotlight120">
1059+
<Platform Name="iOSDevice64">
1060+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1061+
<Operation>1</Operation>
1062+
</Platform>
1063+
<Platform Name="iOSSimulator">
1064+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1065+
<Operation>1</Operation>
1066+
</Platform>
1067+
</DeployClass>
1068+
<DeployClass Name="iPhone_Spotlight80">
1069+
<Platform Name="iOSDevice64">
1070+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1071+
<Operation>1</Operation>
1072+
</Platform>
1073+
<Platform Name="iOSSimulator">
1074+
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir>
1075+
<Operation>1</Operation>
1076+
</Platform>
1077+
</DeployClass>
9291078
<DeployClass Name="ProjectAndroidManifest">
9301079
<Platform Name="Android">
9311080
<Operation>1</Operation>
@@ -1113,6 +1262,7 @@
11131262
<Platform value="Android64">False</Platform>
11141263
<Platform value="iOSDevice64">False</Platform>
11151264
<Platform value="iOSSimulator">False</Platform>
1265+
<Platform value="Linux64">False</Platform>
11161266
<Platform value="OSX64">False</Platform>
11171267
<Platform value="Win32">True</Platform>
11181268
<Platform value="Win64">False</Platform>

0 commit comments

Comments
 (0)