Skip to content

Commit

Permalink
add capability to isplay single task info
Browse files Browse the repository at this point in the history
  • Loading branch information
zamronypj committed Jun 22, 2021
1 parent 3357c4c commit ead9ffe
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 2 deletions.
93 changes: 93 additions & 0 deletions src/Tasks/Implementations/Info/SingleInfoTaskImpl.pas
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*---------------------------------------*)
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.
46 changes: 46 additions & 0 deletions src/Tasks/Implementations/Info/WithSingleInfoTaskImpl.pas
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*---------------------------------------*)
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.
5 changes: 4 additions & 1 deletion src/Tasks/Includes/Info/task.registrations.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)
);
11 changes: 11 additions & 0 deletions src/Tasks/Includes/Info/units.inc
Original file line number Diff line number Diff line change
@@ -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,
2 changes: 1 addition & 1 deletion src/Tasks/Includes/units.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*------------------------------------------------------------- *)

{$INCLUDE Deploy/units.inc}
{$INCLUDE Info/units.inc}

InfoTaskImpl,
KeyGenTaskImpl,
KeyGenTaskFactoryImpl,
GuidGenTaskImpl,
Expand Down

0 comments on commit ead9ffe

Please sign in to comment.