Release 0.2.1
[shpub.git] / src / shpub / Cli.php
index a57b287fda084518f5f47f2066105507be58a45b..19f93d75a0f508ec01af278554e0042188674805 100644 (file)
@@ -27,21 +27,21 @@ class Cli
                     $res->command->options['force']
                 );
                 break;
-            case 'like':
-                $this->requireValidHost();
-                $cmd = new Command_Like($this->cfg->host);
-                $cmd->run($res->command->args['url']);
-                break;
+
             case 'server':
                 $cmd = new Command_Server($this->cfg);
                 $cmd->run($res->command->options['verbose']);
                 break;
+
             default:
-                var_dump($this->cfg->host, $res);
-                Log::err('FIXME');
+                $class = 'shpub\\Command_' . ucfirst($res->command_name);
+                $this->requireValidHost();
+                $cmd = new $class($this->cfg);
+                $cmd->run($res->command);
+                break;
             }
         } catch (\Exception $e) {
-            echo 'Error: ' . $e->getMessage() . "\n";
+            Log::err('Error: ' . $e->getMessage());
             exit(1);
         }
     }
@@ -67,10 +67,13 @@ class Cli
                 } else {
                     $this->cfg->host = $this->cfg->hosts[$key];
                 }
+            } else {
+                $key = $this->cfg->getDefaultHost();
+                if ($key !== null) {
+                    $this->cfg->host = $this->cfg->hosts[$key];
+                }
             }
-            if ($opts['user'] !== null) {
-                $this->cfg->host->user = $opts['user'];
-            }
+            $this->cfg->setDebug($opts['debug']);
 
             return $res;
         } catch (\Exception $exc) {
@@ -86,8 +89,9 @@ class Cli
     protected function loadOptParser()
     {
         $optParser = new \Console_CommandLine();
-        $optParser->description = 'shpub';
-        $optParser->version = '0.0.0';
+        $optParser->name        = 'shpub';
+        $optParser->description = 'Command line micropub client';
+        $optParser->version     = '0.2.1';
         $optParser->subcommand_required = true;
 
         $optParser->addOption(
@@ -102,87 +106,32 @@ class Cli
             )
         );
         $optParser->addOption(
-            'user',
-            array(
-                'short_name'  => '-u',
-                'long_name'   => '--user',
-                'description' => 'User URL',
-                'help_name'   => 'URL',
-                'action'      => 'StoreString',
-                'default'     => null,
-            )
-        );
-
-        $cmd = $optParser->addCommand('connect');
-        $cmd->addOption(
-            'force',
+            'debug',
             array(
-                'short_name'  => '-f',
-                'long_name'   => '--force-update',
-                'description' => 'Force token update if token already available',
+                'short_name'  => '-d',
+                'long_name'   => '--debug',
+                'description' => 'Verbose output',
                 'action'      => 'StoreTrue',
                 'default'     => false,
             )
         );
-        $cmd->addArgument(
-            'server',
-            [
-                'optional'    => false,
-                'description' => 'Server URL',
-            ]
-        );
-        $cmd->addArgument(
-            'user',
-            [
-                'optional'    => false,
-                'description' => 'User URL',
-            ]
-        );
-        $cmd->addArgument(
-            'key',
-            [
-                'optional'    => true,
-                'description' => 'Short name (key)',
-            ]
-        );
 
-        $cmd = $optParser->addCommand('server');
-        $cmd->addOption(
-            'verbose',
-            array(
-                'short_name'  => '-v',
-                'long_name'   => '--verbose',
-                'description' => 'Show more server infos',
-                'action'      => 'StoreTrue',
-                'default'     => false,
-            )
-        );
+        Command_Connect::opts($optParser);
+        Command_Server::opts($optParser);
 
-        //$cmd = $optParser->addCommand('post');
-        $cmd = $optParser->addCommand('reply');
-        $cmd->addArgument(
-            'url',
-            [
-                'optional'    => false,
-                'description' => 'URL that is replied to',
-            ]
-        );
-        $cmd->addArgument(
-            'text',
-            [
-                'optional'    => false,
-                'description' => 'Reply text',
-            ]
-        );
+        Command_Article::opts($optParser);
+        Command_Note::opts($optParser);
+        Command_Reply::opts($optParser);
+        Command_Like::opts($optParser);
+        Command_Repost::opts($optParser);
+        Command_Rsvp::opts($optParser);
+        Command_Bookmark::opts($optParser);
 
-        $cmd = $optParser->addCommand('like');
-        $cmd->addArgument(
-            'url',
-            [
-                'optional'    => false,
-                'description' => 'URL that is liked',
-            ]
-        );
+        Command_Delete::opts($optParser);
+        Command_Undelete::opts($optParser);
+        Command_Update::opts($optParser);
+
+        Command_Upload::opts($optParser);
 
         return $optParser;
     }