From ead9ffe3a74e4884071b860e01c9ee617e959992 Mon Sep 17 00:00:00 2001 From: "Zamrony P. Juhara" Date: Tue, 22 Jun 2021 07:54:33 +0700 Subject: [PATCH] add capability to isplay single task info --- .../Info/SingleInfoTaskImpl.pas | 93 +++++++++++++++++++ .../Info/WithSingleInfoTaskImpl.pas | 46 +++++++++ .../Includes/Info/task.registrations.inc | 5 +- src/Tasks/Includes/Info/units.inc | 11 +++ src/Tasks/Includes/units.inc | 2 +- 5 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 src/Tasks/Implementations/Info/SingleInfoTaskImpl.pas create mode 100644 src/Tasks/Implementations/Info/WithSingleInfoTaskImpl.pas create mode 100644 src/Tasks/Includes/Info/units.inc diff --git a/src/Tasks/Implementations/Info/SingleInfoTaskImpl.pas b/src/Tasks/Implementations/Info/SingleInfoTaskImpl.pas new file mode 100644 index 0000000..d0423b7 --- /dev/null +++ b/src/Tasks/Implementations/Info/SingleInfoTaskImpl.pas @@ -0,0 +1,93 @@ +(*!------------------------------------------------------------ + * Fano CLI Application (https://fanoframework.github.io) + * + * @link https://github.com/fanoframework/fano-cli + * @copyright Copyright (c) 2018 - 2020 Zamrony P. Juhara + * @license https://github.com/fanoframework/fano-cli/blob/master/LICENSE (MIT) + *------------------------------------------------------------- *) +unit SingleInfoTaskImpl; + +interface + +{$MODE OBJFPC} +{$H+} + +uses + + ListIntf, + TaskOptionsIntf, + TaskIntf; + +type + + (*!-------------------------------------- + * Task that display help information + * for single task + * + * @author Zamrony P. Juhara + *---------------------------------------*) + TSingleInfoTask = class(TInterfacedObject, ITask) + private + fTaskList : IList; + public + constructor create(const tasks : IList); + function run( + const opt : ITaskOptions; + const longOpt : shortstring + ) : ITask; + end; + +implementation + +uses + + TaskItemTypes; + + constructor TSingleInfoTask.create(const tasks : IList); + begin + fTaskList := tasks; + end; + + function findTask(const taskList : IList; const taskName : string) : PTaskItem; + var i, taskCount : integer; + item : PTaskItem; + begin + result := nil; + taskCount := taskList.count(); + for i:=0 to taskCount-1 do + begin + item := taskList.get(i); + if taskName = item^.longOption then + begin + result := item; + exit; + end; + end; + end; + + function TSingleInfoTask.run( + const opt : ITaskOptions; + const longOpt : shortstring + ) : ITask; + var taskName : string; + taskItem : PTaskItem; + begin + taskName := opt.getOptionValue('task'); + taskItem := findTask(fTaskList, taskName); + + writeln('Fano CLI, utility for Fano Framework'); + writeln('https://fanoframework.github.io'); + writeln(); + + if (taskItem = nil) then + begin + writeln('Task ' + taskName + ' is not found.'); + end else + begin + writeln('Usage: fanocli --' + taskName + ' [Task Parameters]'); + writeln(); + writeln(' ', taskItem^.description); + end; + result := self; + end; +end. diff --git a/src/Tasks/Implementations/Info/WithSingleInfoTaskImpl.pas b/src/Tasks/Implementations/Info/WithSingleInfoTaskImpl.pas new file mode 100644 index 0000000..53dbc0a --- /dev/null +++ b/src/Tasks/Implementations/Info/WithSingleInfoTaskImpl.pas @@ -0,0 +1,46 @@ +(*!------------------------------------------------------------ + * Fano CLI Application (https://fanoframework.github.io) + * + * @link https://github.com/fanoframework/fano-cli + * @copyright Copyright (c) 2018 - 2020 Zamrony P. Juhara + * @license https://github.com/fanoframework/fano-cli/blob/master/LICENSE (MIT) + *------------------------------------------------------------- *) +unit WithSingleInfoTaskImpl; + +interface + +{$MODE OBJFPC} +{$H+} + +uses + + TaskOptionsIntf, + TaskIntf, + ConditionalCompositeTaskImpl; + +type + + (*!-------------------------------------- + * Task that execute first task if --task + * is set, otherwise run second task + *--------------------------------------------- + * @author Zamrony P. Juhara + *---------------------------------------*) + TWithSingleInfoTask = class(TConditionalCompositeTask) + protected + function condition( + const opt : ITaskOptions; + const longOpt : shortstring + ) : boolean; override; + end; + +implementation + + function TWithSingleInfoTask.condition( + const opt : ITaskOptions; + const longOpt : shortstring + ) : boolean; + begin + result := opt.hasOption('task'); + end; +end. diff --git a/src/Tasks/Includes/Info/task.registrations.inc b/src/Tasks/Includes/Info/task.registrations.inc index 92864d2..0a7e320 100644 --- a/src/Tasks/Includes/Info/task.registrations.inc +++ b/src/Tasks/Includes/Info/task.registrations.inc @@ -11,5 +11,8 @@ appInst.registerTask( 'help', '--help Display help information', - TInfoTask.create(appInst.getTaskList()) + TWithSingleInfoTask.create( + TSingleInfoTask.create(appInst.getTaskList()), + TInfoTask.create(appInst.getTaskList()) + ) ); diff --git a/src/Tasks/Includes/Info/units.inc b/src/Tasks/Includes/Info/units.inc new file mode 100644 index 0000000..6d934fd --- /dev/null +++ b/src/Tasks/Includes/Info/units.inc @@ -0,0 +1,11 @@ +(*!------------------------------------------------------------ + * Fano CLI Application (https://fanoframework.github.io) + * + * @link https://github.com/fanoframework/fano-cli + * @copyright Copyright (c) 2018 - 2020 Zamrony P. Juhara + * @license https://github.com/fanoframework/fano-cli/blob/master/LICENSE (MIT) + *------------------------------------------------------------- *) + +InfoTaskImpl, +SingleInfoTaskImpl, +WithSingleInfoTaskImpl, diff --git a/src/Tasks/Includes/units.inc b/src/Tasks/Includes/units.inc index e4d27c7..9c4374a 100644 --- a/src/Tasks/Includes/units.inc +++ b/src/Tasks/Includes/units.inc @@ -7,8 +7,8 @@ *------------------------------------------------------------- *) {$INCLUDE Deploy/units.inc} +{$INCLUDE Info/units.inc} -InfoTaskImpl, KeyGenTaskImpl, KeyGenTaskFactoryImpl, GuidGenTaskImpl,