Release 0.7.1 master github/master v0.7.1
authorChristian Weiske <cweiske@cweiske.de>
Wed, 5 Sep 2018 20:20:00 +0000 (22:20 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 5 Sep 2018 20:20:00 +0000 (22:20 +0200)
ChangeLog
README.rst
build.xml
src/shpub/Cli.php
src/shpub/Command/AbstractProps.php
src/shpub/Command/Connect.php
src/shpub/Command/Server.php
src/shpub/Config.php
src/shpub/Request.php

index 205321c9831ba00a5b80bdab32ff6e6c5b851a10..ed16f59f6edf4683d537256e48a1ca565b6e22f8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2018-09-05  Christian Weiske  <cweiske@cweiske.de>
+
+       * Fix connection callback "me" parameter requirement
+       * Version 0.7.1
+
+2018-02-05  Christian Weiske  <cweiske@cweiske.de>
+
+       * Add "--dry-run" option
+       * Fix space-after-"-x"-option error
+       * Version 0.7.0
+
+2017-11-13  Christian Weiske  <cweiske@cweiske.de>
+
+       * Add "x" command to post custom types
+       * Version 0.6.0
+
 2017-10-28  Christian Weiske  <cweiske@cweiske.de>
 
        * Fix handling of auth URLs with "?" in them
index 1ac15c981a4272b41adf50525408640463571ca3..813586a235340ae961c1e54540da9487d78b7657 100644 (file)
@@ -18,6 +18,26 @@ See `shpub downloads page <http://cweiske.de/shpub-download.htm>`_
 for all released versions.
 
 
+Installation
+============
+After downloading ``shpub-x.y.z.phar``, you can either use it directly::
+
+    $ php /path/to/shpub-x.y.z.phar --version
+
+or make it more easily accessible::
+
+    $ mv /path/to/shpub-x.y.z.phar /usr/local/bin/shpub
+    $ chmod +x /usr/local/bin/shpub
+    $ shpub --version
+
+You might need ``sudo`` to be able to copy it into the ``/usr/local/bin/``
+directory.
+
+If you're running from the git checkout, start it as follows::
+
+    $ ./bin/shpub.php --version
+
+
 Dependencies
 ============
 When using the git version, you need to have the following dependencies
@@ -35,13 +55,13 @@ Initial setup
 =============
 ::
 
-    $ ./bin/shpub.php connect http://mywebsite
+    $ shpub connect http://mywebsite
 
-Different user::
+In case there are multiple users on the same server::
 
-    $ ./bin/shpub.php connect http://mywebsite http://mywebsite/user
+    $ shpub connect http://sharedwebsite http://shareswebsite/user
 
-If you pass a third parameter, then it will be the name of the connection.
+If you pass a third parameter, then that will be the name of the connection.
 You can select a specific server/connection with ``-s`` on all commands.
 
 
@@ -49,7 +69,7 @@ List configured servers/connections
 ===================================
 ::
 
-    $ ./bin/shpub.php server
+    $ shpub server
     rr
     test
     anoweco.bogo
@@ -71,7 +91,7 @@ shpub has support for the following post types:
 - `repost <http://indieweb.org/repost>`_
 - `rsvp <http://indieweb.org/rsvp>`_
 
-``shpub`` sends data form-encoded by default.
+By default ``shpub`` sends data form-encoded.
 To send JSON requests, use the ``--json`` option.
 
 
@@ -79,7 +99,7 @@ Create a like
 =============
 ::
 
-    $ ./bin/shpub.php like http://example.org/
+    $ shpub like http://example.org/
     Like created at server
     http://anoweco.bogo/comment/23.htm
 
@@ -87,7 +107,7 @@ Create a reply
 ==============
 ::
 
-    $ ./bin/shpub.php reply http://example.org/ "Hey, cool!"
+    $ shpub reply http://example.org/ "Hey, cool!"
     Reply created at server
     http://anoweco.bogo/comment/42.htm
 
@@ -96,13 +116,13 @@ Create a note
 =============
 A normal note::
 
-    $ ./bin/shpub.php note "oh this is cool!"
+    $ shpub note "oh this is cool!"
     Note created at server
     http://known.bogo/2016/oh-this-is-cool.htm
 
 Note with an image::
 
-    $ ./bin/shpub.php note -f image.jpg "this is so cute"
+    $ shpub note -f image.jpg "this is so cute"
     Note created at server
     http://known.bogo/2016/this-is-so-cute
 
@@ -110,13 +130,13 @@ You can use ``-f`` several times to upload multiple files.
 
 URL image upload::
 
-    $ ./bin/shpub.php note -f http://example.org/1.jpg "img url!"
+    $ shpub note -f http://example.org/1.jpg "img url!"
     Note created at server
     http://known.bogo/2016/img-url
 
 Load note content from a file::
 
-    $ ./bin/shpub.php note - < /path/to/file.txt
+    $ shpub note - < /path/to/file.txt
     Note created at server
     http://known.bogo/2017/some-note
 
@@ -125,11 +145,13 @@ Custom post types
 =================
 You may create custom post types with the ``x`` command.
 This is useful if your micropub endpoint supports additional types,
-like known's ``annotation`` type (comments and likes for posts).
+like `known <http://withknown.com/>`__'s
+`"annotation" type <https://cweiske.de/tagebuch/micropub-comments-known.htm>`__
+(comments and likes for posts).
 
 Create a comment to a known post::
 
-    $ ./bin/shpub.php x annotation\
+    $ shpub x annotation\
         -x url=http://known.bogo/2016/example-domain-1\
         -x type=reply\
         -x username=barryf\
@@ -143,11 +165,11 @@ Delete/Undelete
 ===============
 You may delete and restore posts on micropub servers::
 
-    $ ./bin/shpub.php delete http://known.bogo/2016/like
+    $ shpub delete http://known.bogo/2016/like
 
 Restore a deleted post::
 
-    $ ./bin/shpub.php undelete http://known.bogo/2016/like
+    $ shpub undelete http://known.bogo/2016/like
 
 
 =======
@@ -168,33 +190,33 @@ Syndication targets
 ===================
 You may list the syndication targets defined on the server::
 
-    $ ./bin/shpub.php targets
+    $ shpub targets
     IndieNews
      https://news.indieweb.org/en
 
 Then specify it when creating a post::
 
-    $ ./bin/shpub.php article -x mp-syndicate-to=https://news.indieweb.org/en title text
+    $ shpub article -x mp-syndicate-to=https://news.indieweb.org/en title text
 
 ============
 File uploads
 ============
 Most post types allow file uploads. Simply use ``-f``::
 
-    $ ./bin/shpub.php note -f path/to/image.jpg "image test"
+    $ shpub note -f path/to/image.jpg "image test"
     Note created at server
     http://known.bogo/2016/image-test
 
 The media endpoint is used automatically if the micropub endpoint has one.
-To force shpub to directly upload the file and skip the media endpoint,
+To force ``shpub`` to directly upload the file and skip the media endpoint,
 use the ``--direct-upload`` option::
 
-    $ ./bin/shpub.php note --direct-upload -f path/to/image.jpg "direct upload"
+    $ shpub note --direct-upload -f path/to/image.jpg "direct upload"
 
 Use the ``upload`` command to upload files to the media endpoint without
 creating a post::
 
-    $ ./bin/shpub.php upload /path/to/file.jpg /path/to/file2.jpg
+    $ shpub upload /path/to/file.jpg /path/to/file2.jpg
     Uploaded file /path/to/file.jpg
     http://test.bogo/micropub-media-endpoint/1474362040.2941/file.jpg
     Uploaded file /path/to/file2.jpg
@@ -207,12 +229,56 @@ Debugging
 To debug ``shpub`` or your micropub endpoint, use the ``--debug`` option
 to see ``curl`` command equivalents to the shpub HTTP requests::
 
-    $ ./bin/shpub.php -s known -d note "a simple note"
+    $ shpub -s known -d note "a simple note"
     curl -X POST -H 'User-Agent: shpub' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Authorization: Bearer abc' -d 'h=entry' -d 'content=a simple note' 'http://known.bogo/micropub/endpoint'
     Post created at server
     http://known.bogo/2016/a-simple-note
 
 
+See curl commands only
+======================
+You may use the ``--dry-run`` option to make shpub not send any modifying
+HTTP requests (e.g. POST and PUT).
+
+Together with ``--debug`` you can use this to get curl commands without sending
+anything to the server::
+
+    $ shpub --debug --dry-run like example.org
+    curl -X POST -H 'User-Agent: shpub' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Authorization: Bearer cafe' -d 'h=entry' -d 'like-of=http://example.org' 'http://anoweco.bogo/micropub.php'
+    Like created at server
+    http://example.org/fake-response
+
+
+Server information
+==================
+To see which server, user and endpoint URLs ``shpub`` uses, pass the
+server name to the ``server`` command::
+
+    $ shpub server commentpara.de
+    commentpara.de
+     URL:   http://commentpara.de
+     User:  https://commentpara.de/user/3.htm
+     Endpoints:
+      micropub:      https://commentpara.de/micropub.php
+      media:
+      token:         https://commentpara.de/token.php
+      authorization: https://commentpara.de/auth.php
+
+
+===========
+Development
+===========
+
+Releasing a new version
+=======================
+
+#. Add notes to ``ChangeLog``
+#. Update version number in ``build.xml`` and ``src/shpub/Cli.php``
+#. Run ``phing``
+#. Commit and tag the version
+#. In the ``cweiske.de`` directory, run ``./scripts/update-shpub.sh``
+
+
 ===========
 About shpub
 ===========
index 7c8ac5d6d27e8309e3e4a4abf75da01a547eaa47..0f1c6a75a97c83150d66c00f387ea9a8e6fb1207 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <project name="shpub" default="phar" basedir=".">
 
- <property name="version"  value="0.5.2" />
+ <property name="version"  value="0.7.1" />
  <property name="pharfile" value="${phing.dir}/dist/${phing.project.name}-${version}.phar" />
  <property name="libdir" value="${phing.dir}/lib"/>
 
index f1a625986eb1800e2456b47f009d507ae863bb11..354af72aeb6ffa07aa175cb00fbc36162c93c99c 100644 (file)
@@ -78,6 +78,7 @@ class Cli
                 }
             }
             $this->cfg->setDebug($opts['debug']);
+            $this->cfg->setDryRun($opts['dryrun']);
 
             return $res;
         } catch (\Exception $exc) {
@@ -95,7 +96,7 @@ class Cli
         $optParser = new \Console_CommandLine();
         $optParser->name        = 'shpub';
         $optParser->description = 'Command line micropub client';
-        $optParser->version     = '0.5.2';
+        $optParser->version     = '0.7.1';
         $optParser->subcommand_required = true;
 
         $optParser->addOption(
@@ -119,6 +120,17 @@ class Cli
                 'default'     => false,
             )
         );
+        $optParser->addOption(
+            'dryrun',
+            array(
+                'short_name'  => '-n',
+                'long_name'   => '--dry-run',
+                'description' => 'Do not send modifying HTTP request(s)'
+                    . ' to the server',
+                'action'      => 'StoreTrue',
+                'default'     => false,
+            )
+        );
 
         Command_Connect::opts($optParser);
         Command_Server::opts($optParser);
index e186819f49b26a907660a50854f87c028f9ee06f..c893eef3dbdbac8eb9930cf70cb0dc3ea6b02ce8 100644 (file)
@@ -188,6 +188,10 @@ class Command_AbstractProps
         if (count($cmdRes->options['x'])) {
             $postParams = [];
             foreach ($cmdRes->options['x'] as $xproperty) {
+                if ($xproperty == '') {
+                    //happens with "-x foo=bar" instead of "-xfoo=bar"
+                    continue;
+                }
                 list($propkey, $propval) = explode('=', $xproperty, 2);
                 if (!isset($postParams[$propkey])) {
                     $postParams[$propkey] = [];
index 6ac5ed45d2b54302d8b493c0f0a94094611e1f9d..b39665b1c729394335abeb749444d081fd578456 100644 (file)
@@ -279,7 +279,6 @@ class Command_Connect
                     parse_str($parts['query'], $query);
                     if (isset($query['code'])
                         && isset($query['state'])
-                        && isset($query['me'])
                     ) {
                         fwrite($sock, $responseOk);
                         fclose($sock);
index b0200f22ce36611371abdaa0587914eb8d1d1540..3ce0c736456f796cf4bee7dff09001eccedef456 100644 (file)
@@ -18,7 +18,9 @@ class Command_Server
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('server');
-        $cmd->description = 'List all connections';
+        $cmd->description = 'List all connections'
+            . "\nPass the connection name to see all details:"
+            . " URL, user, endpoint URLs";
         $cmd->addOption(
             'verbose',
             array(
index 2ca7d9adeea3c376196ebe0972fd313d53879ba0..f3ca5433d13a94904a6aeeae0148bafb28b9baf0 100644 (file)
@@ -14,6 +14,8 @@ class Config
 
     public $debug = false;
 
+    public $dryRun = false;
+
     protected function getConfigFilePath()
     {
         if (!isset($_SERVER['HOME'])) {
@@ -91,7 +93,7 @@ class Config
                 return $key;
             }
         }
-        
+
         reset($this->hosts);
         return key($this->hosts);
     }
@@ -121,5 +123,10 @@ class Config
     {
         $this->debug = $debug;
     }
+
+    public function setDryRun($dryRun)
+    {
+        $this->dryRun = $dryRun;
+    }
 }
 ?>
index dce163f42a2c51f470cb9fe13000b262f4cec9fe..e7c3b775a51c26d76320bd400b671059d31c1c97 100644 (file)
@@ -93,6 +93,17 @@ class Request
             $cp = new CurlPrinter();
             $cp->show($this->req, $this->uploadsInfo, $this->dedicatedBody);
         }
+
+        if ($this->cfg->dryRun && $this->req->getMethod() != 'GET') {
+            //do not run any modifying queries
+            //fake a successful response
+            $res = new \HTTP_Request2_Response('HTTP/1.1 200 OK', false);
+            $res->parseHeaderLine('Content-type: text/plain');
+            $res->parseHeaderLine('Location: http://example.org/fake-response');
+            $res->appendBody('Fake --dry-run response');
+            return $res;
+        }
+
         $res = $this->req->send();
 
         if (intval($res->getStatus() / 100) != 2) {