forked from zamronypj/fano-cli
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add capability to isplay single task info
- Loading branch information
Showing
5 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters