$cmd->run($res->command->options['verbose']);
break;
- case 'like':
- $this->requireValidHost();
- $cmd = new Command_Like($this->cfg);
- $cmd->run($res->command->args['url']);
- break;
-
- case 'reply':
+ default:
+ $class = 'shpub\\Command_' . ucfirst($res->command_name);
$this->requireValidHost();
- $cmd = new Command_Reply($this->cfg);
- $cmd->run(
- $res->command->args['url'],
- implode(' ', $res->command->args['text'])
- );
+ $cmd = new $class($this->cfg);
+ $cmd->run($res->command);
break;
-
- default:
- var_dump($this->cfg->host, $res);
- Log::err('FIXME');
}
} catch (\Exception $e) {
echo 'Error: ' . $e->getMessage() . "\n";
)
);
- //$cmd = $optParser->addCommand('post');
- $cmd = $optParser->addCommand('reply');
- $cmd->addArgument(
- 'url',
- [
- 'optional' => false,
- 'description' => 'URL that is replied to',
- ]
- );
- $cmd->addArgument(
- 'text',
- [
- 'optional' => false,
- 'multiple' => true,
- 'description' => 'Reply text',
- ]
- );
-
- $cmd = $optParser->addCommand('like');
- $cmd->addArgument(
- 'url',
- [
- 'optional' => false,
- 'description' => 'URL that is liked',
- ]
- );
+ Command_Note::opts($optParser);
+ Command_Reply::opts($optParser);
+ Command_Like::opts($optParser);
return $optParser;
}
$this->cfg = $cfg;
}
- public function run($url)
+ public static function opts(\Console_CommandLine $optParser)
{
- $url = Validator::url($url, 'url');
+ $cmd = $optParser->addCommand('like');
+ $cmd->addArgument(
+ 'url',
+ [
+ 'optional' => false,
+ 'description' => 'URL that is liked',
+ ]
+ );
+ }
+
+ public function run($command)
+ {
+ $url = Validator::url($command->args['url'], 'url');
if ($url === false) {
exit(10);
}
--- /dev/null
+<?php
+namespace shpub;
+
+class Command_Note
+{
+ /**
+ * @var Config
+ */
+ protected $cfg;
+
+ public function __construct($cfg)
+ {
+ $this->cfg = $cfg;
+ }
+
+ public static function opts(\Console_CommandLine $optParser)
+ {
+ $cmd = $optParser->addCommand('note');
+ $cmd->addArgument(
+ 'text',
+ [
+ 'optional' => false,
+ 'multiple' => false,
+ 'description' => 'Post text',
+ ]
+ );
+ }
+
+ public function run($command)
+ {
+ $data = [
+ 'h' => 'entry',
+ 'content' => $command->args['text'],
+ ];
+
+ $body = http_build_query($data);
+
+ $req = new Request($this->cfg->host, $this->cfg);
+ $res = $req->send($body);
+ $postUrl = $res->getHeader('Location');
+ echo "Post created at server\n";
+ echo $postUrl . "\n";
+ }
+}
+?>
$this->cfg = $cfg;
}
+ public static function opts(\Console_CommandLine $optParser)
+ {
+ $cmd = $optParser->addCommand('reply');
+ $cmd->addArgument(
+ 'url',
+ [
+ 'optional' => false,
+ 'description' => 'URL that is replied to',
+ ]
+ );
+ $cmd->addArgument(
+ 'text',
+ [
+ 'optional' => false,
+ 'multiple' => true,
+ 'description' => 'Reply text',
+ ]
+ );
+ }
public function run($url, $text)
{
$url = Validator::url($url, 'url');