Skip to content

Commit

Permalink
move list and docstring from py3status to py3-cmd (ultrabug#1713)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasers authored Feb 28, 2019
1 parent 0bb3038 commit 2b541d7
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 139 deletions.
4 changes: 2 additions & 2 deletions doc/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ You can get a list with short descriptions of all available modules by using the

.. code-block:: shell
$ py3status list --all
$ py3-cmd list --all
To get more details about all available modules and their configuration, use:

.. code-block:: shell
$ py3status list --all --full
$ py3-cmd list --all --full
All modules shipped with py3status are present as the Python source files in
the ``py3status/modules`` directory.
Expand Down
4 changes: 2 additions & 2 deletions doc/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ py3status comes with a large selection of modules ready to use. For information
You can also get a list with short descriptions of all available modules by using the CLI:
::

$ py3status list --all
$ py3-cmd list --all


To get more details about all available modules and their configuration, use:
::

$ py3status list --all --full
$ py3-cmd list --all --full


.. include:: modules-info.inc
109 changes: 2 additions & 107 deletions py3status/argparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,6 @@
from platform import python_version
from py3status.version import version

LIST_EPILOG = """
examples:
list:
# list one or more modules
py3status list clock loadavg xrandr # full
py3status list coin* git* w* # fnmatch
# list all modules
py3status list --all
# show full (i.e. docstrings)
py3status list -f static_string
"""

DOCSTRING_EPILOG = """
examples:
check:
# check one or more docstrings
py3status docstring --check clock loadavg xrandr
# check all docstrings
py3status docstring --check
diff:
# show diff docstrings
py3status docstring --diff
update:
# update one or more docstrings
py3status docstring --update clock loadavg xrandr
# update modules according to README.md
py3status docstring --update modules
"""


def parse_cli_args():
"""
Expand Down Expand Up @@ -85,7 +50,7 @@ def error(self, message):
self.print_help()
self.exit(1)

# hide docstring on errors
# hide choices on errors
def _check_value(self, action, value):
if action.choices is not None and value not in action.choices:
raise argparse.ArgumentError(
Expand Down Expand Up @@ -193,43 +158,6 @@ def _format_action_invocation(self, action):
# deprecations
parser.add_argument("-n", "--interval", help=argparse.SUPPRESS)

# make subparsers
subparsers = parser.add_subparsers(dest="command", metavar="{list}")
sps = {}

# list subparser and its args
sps["list"] = subparsers.add_parser(
"list",
epilog=LIST_EPILOG,
formatter_class=argparse.RawTextHelpFormatter,
help="list modules",
)
sps["list"].add_argument(
"-f", "--full", action="store_true", help="show full (i.e. docstrings)"
)
list_group = sps["list"].add_mutually_exclusive_group()
for name in ["all", "core", "user"]:
list_group.add_argument(
"--%s" % name, action="store_true", help="show %s modules" % name
)

# docstring subparser and its args
sps["docstring"] = subparsers.add_parser(
"docstring",
epilog=DOCSTRING_EPILOG,
formatter_class=argparse.RawTextHelpFormatter,
# help="docstring utility",
)
docstring_group = sps["docstring"].add_mutually_exclusive_group()
for name in ["check", "diff", "update"]:
docstring_group.add_argument(
"--%s" % name, action="store_true", help="%s docstrings" % name
)

# modules not required
for name in ["list", "docstring"]:
sps[name].add_argument(nargs="*", dest="module", help="module name")

# parse options, command, etc
options = parser.parse_args()

Expand Down Expand Up @@ -258,43 +186,10 @@ def _format_action_invocation(self, action):
for path in options.include_paths:
path = os.path.abspath(path)
if os.path.isdir(path) and os.listdir(path):
include_paths.append(path + "/")
include_paths.append(path)
options.include_paths = include_paths

# handle py3status list and docstring options
if options.command:
import py3status.docstrings as docstrings

config = vars(options)
modules = [x.rsplit(".py", 1)[0] for x in config["module"]]
# list module names and details
if config["command"] == "list":
tests = [not config[x] for x in ["all", "user", "core"]]
if all([not modules] + tests):
msg = "missing positional or optional arguments"
sps["list"].error(msg)
docstrings.show_modules(config, modules)
# docstring formatting and checking
elif config["command"] == "docstring":
if config["check"]:
docstrings.check_docstrings(False, config, modules)
elif config["diff"]:
docstrings.check_docstrings(True, config, None)
elif config["update"]:
if not modules:
msg = "missing positional arguments or `modules`"
sps["docstring"].error(msg)
if "modules" in modules:
docstrings.update_docstrings()
else:
docstrings.update_readme_for_modules(modules)
else:
msg = "missing positional or optional arguments"
sps["docstring"].error(msg)
parser.exit()

# defaults
del options.command
del options.interval
del options.print_version
options.minimum_interval = 0.1 # minimum module update interval
Expand Down
Loading

0 comments on commit 2b541d7

Please sign in to comment.