From a8bb91ba9baf4c7a8f757345300595ee665d460a Mon Sep 17 00:00:00 2001
From: Holger Nahrstaedt <holger@nahrstaedt.de>
Date: Tue, 1 May 2018 13:43:42 +0200
Subject: [PATCH] Add complete help for beempy and configuration

* configuration improved
* beempy help for each command added
---
 beem/account.py        |   4 +-
 beem/asciichart.py     |  10 ++--
 beem/instance.py       |   2 +-
 beem/profile.py        |   5 +-
 docs/cli.rst           |  10 +++-
 docs/conf.py           |   2 +-
 docs/configuration.rst | 123 ++++++++++++++++++++++++++++++++++++++++-
 docs/requirements.txt  |   1 +
 tox.ini                |   1 +
 9 files changed, 143 insertions(+), 15 deletions(-)

diff --git a/beem/account.py b/beem/account.py
index 7411ca3d..817dd803 100644
--- a/beem/account.py
+++ b/beem/account.py
@@ -184,8 +184,8 @@ class Account(BlockchainObject):
 
             >>> from beem.account import Account
             >>> account = Account("test")
-            >>> print(account.get_similar_account_names(limit=5))
-            ['test', 'test-1', 'test-2', 'test-ico', 'test-ilionx-123']
+            >>> len(account.get_similar_account_names(limit=5))
+            5
 
         """
         if self.steem.rpc.get_use_appbase():
diff --git a/beem/asciichart.py b/beem/asciichart.py
index b06b7f90..b8822344 100644
--- a/beem/asciichart.py
+++ b/beem/asciichart.py
@@ -87,7 +87,7 @@ class AsciiChart(object):
                 chart.new_chart()
                 chart.add_axis()
                 chart.add_curve(series)
-                print(str(chart))  # doctest: +SKIP
+                print(str(chart))
 
         """
         self.minimum = min(series)
@@ -134,7 +134,7 @@ class AsciiChart(object):
                 from beem.asciichart import AsciiChart
                 chart = AsciiChart()
                 series = [1, 2, 3, 7, 2, -4, -2]
-                chart.plot(series)  # doctest: +SKIP
+                chart.plot(series)
         """
         self.clear_data()
         self.adapt_on_series(series)
@@ -158,7 +158,7 @@ class AsciiChart(object):
                 chart.new_chart()
                 chart.add_axis()
                 chart.add_curve(series)
-                print(str(chart))  # doctest: +SKIP
+                print(str(chart))
 
         """
         if minimum is not None:
@@ -182,7 +182,7 @@ class AsciiChart(object):
                 chart.new_chart()
                 chart.add_axis()
                 chart.add_curve(series)
-                print(str(chart))  # doctest: +SKIP
+                print(str(chart))
 
         """
         # axis and labels
@@ -220,7 +220,7 @@ class AsciiChart(object):
                 chart.new_chart()
                 chart.add_axis()
                 chart.add_curve(series)
-                print(str(chart))  # doctest: +SKIP
+                print(str(chart))
 
         """
         if self.n is None:
diff --git a/beem/instance.py b/beem/instance.py
index 2efe17fe..ec89ca24 100644
--- a/beem/instance.py
+++ b/beem/instance.py
@@ -38,7 +38,7 @@ def set_shared_steem_instance(steem_instance):
     """ This method allows us to override default steem instance for all users of
         ``SharedInstance.instance``.
 
-        :param steem.steem.Steem steem_instance: Steem instance
+        :param beem.steem.Steem steem_instance: Steem instance
     """
     clear_cache()
     SharedInstance.instance = steem_instance
diff --git a/beem/profile.py b/beem/profile.py
index c44397ec..10896572 100644
--- a/beem/profile.py
+++ b/beem/profile.py
@@ -16,8 +16,9 @@ class DotDict(dict):
                 >>> from beem.profile import Profile
                 >>> keys = ['profile.url', 'profile.img']
                 >>> values = ["http:", "foobar"]
-                >>> print(Profile(keys, values))
-                {"profile": {"url": "http:", "img": "foobar"}}
+                >>> p = Profile(keys, values)
+                >>> print(p["profile"]["url"])
+                http:
 
         """
         if len(args) == 2:
diff --git a/docs/cli.rst b/docs/cli.rst
index 9ddd26a5..09f1f861 100644
--- a/docs/cli.rst
+++ b/docs/cli.rst
@@ -90,9 +90,15 @@ If you've set up your `default_account`, you can now send funds by omitting this
 
     beempy transfer <recipient_name> 100 STEEM memo
 
+Commands
+--------
 
-Help
-----
+.. click:: beem.cli:cli
+    :prog: beempy
+    :show-nested:
+
+beempy --help
+-------------
 You can see all available commands with ``beempy --help``
 
 ::
diff --git a/docs/conf.py b/docs/conf.py
index df582ea7..a636dedd 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -31,7 +31,7 @@ sys.path.insert(0, os.path.abspath('../scripts/'))
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
 # ones.
-extensions = ["sphinx.ext.autodoc", "sphinx.ext.doctest"]
+extensions = ["sphinx.ext.autodoc", "sphinx.ext.doctest", "sphinx_click.ext"]
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ['_templates']
diff --git a/docs/configuration.rst b/docs/configuration.rst
index b69c73a9..278165a5 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -5,9 +5,11 @@ Configuration
 The pysteem library comes with its own local configuration database
 that stores information like
 
-* API node URL
+* API node URLs
 * default account name
 * the encrypted master password
+* the default voting weight
+* if keyring should be used for unlocking the wallet
 
 and potentially more.
 
@@ -21,10 +23,127 @@ You can access those variables like a regular dictionary by using
 
 Keys can be added and changed like they are for regular dictionaries.
 
-If you don't want to load the :class:`steem.Steem` class, you
+If you don't want to load the :class:`beem.Steem` class, you
 can load the configuration directly by using:
 
 .. code-block:: python
 
     from beem.storage import configStorage as config
 
+It is also possible to access the configuration with the commandline tool `beempy`:
+
+.. code-block:: bash
+
+    beempy config
+
+API node URLs
+-------------
+
+The default node URLs which will be used when  `node` is  `None` in :class:`beem.Steem` class
+is stored in `config["nodes"]` as string. The list can be get and set by:
+
+.. code-block:: python
+
+    from beem import Steem
+    steem = Steem()
+    node_list = steem.get_default_nodes()
+    node_list = node_list[1:] + [node_list[0]]
+    steem.set_default_nodes(node_list)
+
+beempy can also be used to set nodes:
+
+.. code-block:: bash
+
+        beempy set nodes wss://steemd.privex.io
+        beempy set nodes "['wss://steemd.privex.io', 'wss://gtg.steem.house:8090']"
+
+The default nodes can be resetted to the default value. When the first node does not
+answer, steem should be set to the offline mode. This can be done by:
+
+.. code-block:: bash
+
+        beempy -o set nodes ""
+
+or
+
+.. code-block:: python
+
+    from beem import Steem
+    steem = Steem(offline=True)
+    steem.set_default_nodes("")
+
+Default account
+---------------
+
+The default account name is used in some functions, when no account name is given.
+It is also used in  `beempy` for all account related functions.
+
+.. code-block:: python
+
+    from beem import Steem
+    steem = Steem()
+    steem.set_default_account("test")
+    steem.config["default_account"] = "test"
+
+or by beempy with
+
+.. code-block:: bash
+
+        beempy set default_account test
+
+Default voting weight
+---------------------
+
+The default vote weight is used for voting, when no vote weight is given.
+
+.. code-block:: python
+
+    from beem import Steem
+    steem = Steem()
+    steem.config["default_vote_weight"] = 100
+
+or by beempy with
+
+.. code-block:: bash
+
+        beempy set default_vote_weight 100
+
+
+Setting password_storage
+------------------------
+
+The password_storage can be set to:
+
+* environment, this is the default setting. The master password for the wallet can be provided in the environment variable `UNLOCK`.
+* keyring
+
+.. code-block:: python
+
+    from beem import Steem
+    steem = Steem()
+    steem.config["password_storage"] = "environment"
+    steem.config["password_storage"] = "keyring"
+
+or by beempy with
+
+.. code-block:: bash
+
+        beempy set password_storage environment
+        beempy set password_storage keyring
+
+Testing if the master password is correctly provided by keyring or the `UNLOCK` variable:
+
+.. code-block:: python
+
+    from beem import Steem
+    steem = Steem()
+    print(steem.wallet.locked())
+
+When the output is False, automatic unlocking with keyring or the `UNLOCK` variable works.
+It can also tested by beempy with
+
+.. code-block:: bash
+
+        beempy walletinfo --test-unlock
+
+When no password prompt is shown, unlocking with keyring or the `UNLOCK` variable works.
diff --git a/docs/requirements.txt b/docs/requirements.txt
index d392dadc..fed1bfab 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -16,3 +16,4 @@ appdirs
 Click
 prettytable
 sphinx_rtd_theme
+sphinx-click
diff --git a/tox.ini b/tox.ini
index bb4551ad..4c87d149 100644
--- a/tox.ini
+++ b/tox.ini
@@ -128,6 +128,7 @@ changedir=
     docs
 deps=-rdocs/requirements.txt
      sphinx
+     sphinx-click
 commands=
     sphinx-build -b html ./ ./html
 
-- 
GitLab