piknik

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

commit d076f1deea0cea20a88de26bedec9f0a00b07a3b
parent 2505733db65aacf67c7c870e3f33dacb75b6a936
Author: lash <dev@holbrook.no>
Date:   Sun, 19 Mar 2023 20:38:40 +0000

Manual implementation of subcommands

Diffstat:
Mpiknik/cli/add.py | 3+--
Mpiknik/cli/comment.py | 18+++++++++---------
Mpiknik/cli/mod.py | 25++++++++++++-------------
Mpiknik/cli/show.py | 10+++++-----
Mpiknik/runnable/cmd.py | 35++++++++++++++++++++++-------------
5 files changed, 49 insertions(+), 42 deletions(-)

diff --git a/piknik/cli/add.py b/piknik/cli/add.py @@ -8,8 +8,7 @@ ctx = None def subparser(argp): - arg = argp.add_parser('add') - arg.add_argument('title', type=str, nargs='*', help='issue title') + argp.add_argument('title', type=str, nargs='*', help='issue title') return argp diff --git a/piknik/cli/comment.py b/piknik/cli/comment.py @@ -8,16 +8,16 @@ ctx = None def subparser(argp): - arg = argp.add_parser('comment') - arg.add_argument('-s', '--sign-as', dest='s', type=str, help='PGP fingerprint of key to sign issue update with') - arg.add_argument('-r', type=str, action='append', default=[], help='Add literal message text') - arg.add_argument('-f', type=str, action='append', default=[], help='Add arbitrary file as content') + argp.add_argument('-s', '--sign-as', dest='s', type=str, help='PGP fingerprint of key to sign issue update with') + argp.add_argument('-x', '--text', dest='x', type=str, action='append', default=[], help='Add literal message text') + argp.add_argument('-y', '--file', dest='y', type=str, action='append', default=[], help='Add arbitrary file as content') return argp def assembler(o, arg): - o.r = arg.r - o.f = arg.f + o.x = arg.x + o.y = arg.y + o.s = arg.s next_i = 1 @@ -30,7 +30,7 @@ def next_message_arg(): next_i += 1 return None - if r[1] not in ['r', 'i', 't', 'f']: + if r[1] not in ['r', 'i', 'x', 'y']: next_i += 1 return None @@ -49,9 +49,9 @@ def main(): if r == None: continue - if r[0] == 'r': + if r[0] == 'x': messages.append('s:' + r[1]) - elif r[0] == 'f': + elif r[0] == 'y': messages.append('f:' + r[1]) ctx.basket.msg(ctx.issue_id, *messages) diff --git a/piknik/cli/mod.py b/piknik/cli/mod.py @@ -7,21 +7,20 @@ ctx = None def subparser(argp): - arg = argp.add_parser('mod') - arg.add_argument('--accept', action='store_true', help='Accept proposed issue') - arg.add_argument('--block', action='store_true', help='Set issue as blocked') - arg.add_argument('--unblock', action='store_true', help='Set issue as unblocked') - arg.add_argument('--finish', action='store_true', help='Set issue as finished (alias of -s finish)') - arg.add_argument('-s', '--state', type=str, help='Move to state') - arg.add_argument('-t', '--tag', type=str, action='append', default=[], help='Add tag to issue') - arg.add_argument('-u', '--untag', type=str, action='append', default=[], help='Remove tag from issue') + argp.add_argument('--accept', action='store_true', help='Accept proposed issue') + argp.add_argument('--block', action='store_true', help='Set issue as blocked') + argp.add_argument('--unblock', action='store_true', help='Set issue as unblocked') + argp.add_argument('--finish', action='store_true', help='Set issue as finished (alias of -s finish)') + argp.add_argument('-s', '--state', type=str, help='Move to state') + argp.add_argument('-t', '--tag', type=str, action='append', default=[], help='Add tag to issue') + argp.add_argument('-u', '--untag', type=str, action='append', default=[], help='Remove tag from issue') #argp.add_argument('-f', '--file', type=str, action='append', help='Add message file part') #argp.add_argument('-m', '--message', type=str, action='append', default=[], help='Add message text part') - arg.add_argument('-a', '--assign', type=str, action='append', default=[], help='Assign given identity to issue') - arg.add_argument('--unassign', type=str, action='append', default=[], help='Unassign given identity from issue') - arg.add_argument('-o', '--owner', type=str, help='Set given identity as owner of issue') - arg.add_argument('--dep', action='append', default=[], type=str, help='Set issue dependency') - arg.add_argument('--undep', action='append', default=[], type=str, help='Remove issue dependency') + argp.add_argument('-a', '--assign', type=str, action='append', default=[], help='Assign given identity to issue') + argp.add_argument('--unassign', type=str, action='append', default=[], help='Unassign given identity from issue') + argp.add_argument('--owner', type=str, help='Set given identity as owner of issue') + argp.add_argument('--dep', action='append', default=[], type=str, help='Set issue dependency') + argp.add_argument('--undep', action='append', default=[], type=str, help='Remove issue dependency') return argp diff --git a/piknik/cli/show.py b/piknik/cli/show.py @@ -2,6 +2,7 @@ import os import logging import importlib +import argparse # local imports from piknik import Issue @@ -45,11 +46,10 @@ def reset_accumulator(): def subparser(argp): - arg = argp.add_parser('show') - arg.add_argument('-r', '--renderer', type=str, default='default', help='Renderer module for output') - arg.add_argument('-s', '--state', type=str, action='append', default=[], help='Limit results to state(s)') - arg.add_argument('--show-finished', dest='show_finished', action='store_true', help='Include finished issues') - arg.add_argument('--reverse', action='store_true', help='Sort comments by oldest first') + argp.add_argument('-r', '--renderer', type=str, default='default', help='Renderer module for output') + argp.add_argument('-s', '--state', type=str, action='append', default=[], help='Limit results to state(s)') + argp.add_argument('--show-finished', dest='show_finished', action='store_true', help='Include finished issues') + argp.add_argument('--reverse', action='store_true', help='Sort comments by oldest first') return argp diff --git a/piknik/runnable/cmd.py b/piknik/runnable/cmd.py @@ -8,6 +8,7 @@ import tempfile from base64 import b64decode from email.utils import parsedate_to_datetime import importlib +import copy # local imports from piknik.cli import Context @@ -24,25 +25,33 @@ argp.add_argument('-d', type=str, help='Data directory') argp.add_argument('-f', '--files', dest='f', action='store_true', help='Save attachments to filesystem') argp.add_argument('-o', '--files-dir', dest='files_dir', type=str, help='Directory to output saved files to') argp.add_argument('-i','--issue-id', type=str, help='Issue id to show') - -argsub = argp.add_subparsers(title='subcommand', dest='subcmd') -argsub = subparser_show(argsub) -argsub = subparser_mod(argsub) -argsub = subparser_add(argsub) -argsub = subparser_comment(argsub) -arg = argp.parse_args(sys.argv[1:]) +argp.add_argument('cmd', type=str, help='subcommand to execute') +strargs = copy.copy(sys.argv[1:]) +try: + strargs.remove('-h') +except ValueError: + pass +try: + strargs.remove('--help') +except ValueError: + pass +arg, unknown = argp.parse_known_args(strargs) m = None -if arg.subcmd == 'show': +if arg.cmd == 'show': m = importlib.import_module('piknik.cli.show') -elif arg.subcmd == 'mod': - m = importlib.import_module('piknik.cli.mod') -elif arg.subcmd == 'add': +elif arg.cmd == 'add': m = importlib.import_module('piknik.cli.add') -elif arg.subcmd == 'comment': +elif arg.cmd == 'mod': + m = importlib.import_module('piknik.cli.mod') +elif arg.cmd == 'comment': m = importlib.import_module('piknik.cli.comment') else: - raise ValueError('invalid subcommand: ' + arg.subcmd) + raise ValueError('unknown subcommand') + + +argp = m.subparser(argp) +arg = argp.parse_args(sys.argv[1:]) m.ctx = Context(arg, m.assembler)