Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit e67b718

Browse files
committed
Fixes #13 && Better Extension CLI Interface
1 parent 51d3db5 commit e67b718

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

core/CLIParser.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class CLIParser {
33

44
private array $args = array();
55
private bool $empty = true;
6+
private array $plainArgs = array();
67

78
const TASK_VERSION = 'v', TASK_HELP = 'h', TASK_STATS = 's',
89
TASK_SETTINGS = 'p', TASK_RECORD = 'r', TASK_PAUSE = 'e',
@@ -19,6 +20,7 @@ class CLIParser {
1920
);
2021

2122
public function __construct(int $argc, array $argv) {
23+
$this->plainArgs = $argv;
2224
if( $argc > 0){
2325
$this->args = array_slice($argv, 1);
2426
$this->args = array_map('trim', $this->args);
@@ -73,5 +75,9 @@ public function getCommands() : array {
7375
}
7476
return array('');
7577
}
78+
79+
public function getPlainArgs() : array {
80+
return $this->plainArgs;
81+
}
7682
}
7783
?>

core/ExtensionEventHandler.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,20 @@ public static function loadExtension( string $name, array $events , string $file
3535

3636
public static function cli( string $name, CLIParser $parser, CLIOutput $output, string $callback ) : void {
3737
self::ensureExtensionLoaded($name);
38-
$callback($parser, $output);
38+
if($parser->getTask() !== CLIParser::TASK_EXTENSION){
39+
// shortcut used, we will reconstruct full parser (tasks/ commands)!!
40+
$oldArgs = $parser->getPlainArgs();
41+
$newArgs = array_merge(array(
42+
$oldArgs[0],
43+
CLIParser::TASK_EXTENSION,
44+
$name
45+
), array_slice($oldArgs, 2));
46+
$p = new CLIParser(count($newArgs), $newArgs );
47+
}
48+
else{
49+
$p = $parser;
50+
}
51+
$callback($p, $output);
3952
}
4053

4154
private static function event( string $event, ...$args ) : void {

core/Utilities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
class Utilities {
66

7-
const VERSION = 'v0.9.7 beta';
7+
const VERSION = 'v0.9.8 beta';
88

99
/**
1010
* OS Consts

extensions/milog/index.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ class MiLog {
77
private static array $data;
88

99
public static function cli( \CLIParser $parser, \CLIOutput $output ) : void {
10+
$newArgs = $parser->getCommands();
11+
array_unshift( $newArgs, \CLIParser::TASK_STATS );
12+
$p = new \CLIParser(count($newArgs), $newArgs);
13+
1014
self::$isMiLogOutput = true;
1115
\ob_start();
1216

1317
$o = new \CLIOutput();
14-
$s = new \Stats($parser, $o);
18+
$s = new \Stats($p, $o);
1519
$o->__destruct();
1620
unset($o);
1721

@@ -21,7 +25,9 @@ public static function cli( \CLIParser $parser, \CLIOutput $output ) : void {
2125
$output->print(
2226
array('MiLog',
2327
array(
24-
'Please give the same commands to filter data as used in the statistics view.',
28+
'Please give the same commands to filter data as used in the statistics view, e.g.',
29+
\CLIOutput::colorString('ttt ext milog week -cats "Hobby"', \CLIOutput::BLUE),
30+
\CLIOutput::colorString('ttt ml all', \CLIOutput::BLUE),
2531
)
2632
));
2733

0 commit comments

Comments
 (0)