]> git.mxchange.org Git - friendica.git/blob - src/Core/Console.php
Add new commands to base console help text
[friendica.git] / src / Core / Console.php
1 <?php\r
2 \r
3 namespace Friendica\Core;\r
4 \r
5 /**\r
6  * Description of Console\r
7  *\r
8  * @author Hypolite Petovan <mrpetovan@gmail.com>\r
9  */\r
10 class Console extends \Asika\SimpleConsole\Console\r
11 {\r
12         // Disables the default help handling\r
13         protected $helpOptions = [];\r
14         protected $customHelpOptions = ['h', 'help', '?'];\r
15 \r
16         protected function getHelp()\r
17         {\r
18 \r
19 \r
20                 $help = <<<HELP\r
21 Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]\r
22 \r
23 Commands:\r
24         config                 Edit site config\r
25         createdoxygen          Generate Doxygen headers\r
26         docbloxerrorchecker    Check the file tree for DocBlox errors\r
27         extract                Generate translation string file for the Friendica project (deprecated)\r
28         globalcommunityblock   Block remote profile from interacting with this node\r
29         globalcommunitysilence Silence remote profile from global community page\r
30         help                   Show help about a command, e.g (bin/console help config)\r
31         maintenance            Set maintenance mode for this node\r
32         php2po                 Generate a messages.po file from a strings.php file\r
33 \r
34 Options:\r
35         -h|--help|-? Show help information\r
36         -v           Show more debug information.\r
37 HELP;\r
38                 return $help;\r
39         }\r
40 \r
41         protected function doExecute()\r
42         {\r
43                 if ($this->getOption('v')) {\r
44                         $this->out('Executable: ' . $this->executable);\r
45                         $this->out('Arguments: ' . var_export($this->args, true));\r
46                         $this->out('Options: ' . var_export($this->options, true));\r
47                 }\r
48 \r
49                 $showHelp = false;\r
50                 $subHelp = false;\r
51                 $command = null;\r
52 \r
53                 if ($this->getOption('version')) {\r
54                         $this->out('Friendica Console version ' . FRIENDICA_VERSION);\r
55 \r
56                         return 0;\r
57                 } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0\r
58                 ) {\r
59                         $showHelp = true;\r
60                 } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {\r
61                         $command = $this->getArgument(1);\r
62                         $subHelp = true;\r
63                         array_shift($this->args);\r
64                         array_shift($this->args);\r
65                 } elseif (count($this->args) >= 1) {\r
66                         $command = $this->getArgument(0);\r
67                         array_shift($this->args);\r
68                 }\r
69 \r
70                 if (is_null($command)) {\r
71                         $this->out($this->getHelp());\r
72                         return 0;\r
73                 }\r
74 \r
75                 $console = $this->getSubConsole($command);\r
76 \r
77                 if ($subHelp) {\r
78                         $console->setOption($this->customHelpOptions, true);\r
79                 }\r
80 \r
81                 return $console->execute();\r
82         }\r
83 \r
84         private function getSubConsole($command)\r
85         {\r
86                 if ($this->getOption('v')) {\r
87                         $this->out('Command: ' . $command);\r
88                 }\r
89 \r
90                 $subargs = $this->args;\r
91                 array_unshift($subargs, $this->executable);\r
92 \r
93                 $subconsole = null;\r
94 \r
95                 switch ($command) {\r
96                         case 'config' : $subconsole = new Console\Config($subargs);\r
97                                 break;\r
98                         case 'createdoxygen' : $subconsole = new Console\CreateDoxygen($subargs);\r
99                                 break;\r
100                         case 'docbloxerrorchecker' : $subconsole = new Console\DocBloxErrorChecker($subargs);\r
101                                 break;\r
102                         case 'extract' : $subconsole = new Console\Extract($subargs);\r
103                                 break;\r
104                         case 'globalcommunityblock': $subconsole = new Console\GlobalCommunityBlock($subargs);\r
105                                 break;\r
106                         case 'globalcommunitysilence': $subconsole = new Console\GlobalCommunitySilence($subargs);\r
107                                 break;\r
108                         case 'maintenance': $subconsole = new Console\Maintenance($subargs);\r
109                                 break;\r
110                         case 'php2po': $subconsole = new Console\PhpToPo($subargs);\r
111                                 break;\r
112                         default:\r
113                                 throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');\r
114                 }\r
115 \r
116                 foreach ($this->options as $name => $value) {\r
117                         $subconsole->setOption($name, $value);\r
118                 }\r
119 \r
120                 return $subconsole;\r
121         }\r
122 \r
123 }\r