From 605264c0f7fc853dc7f5dadd674bf4be954ffdbb Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sun, 1 Aug 2021 11:18:15 -0400 Subject: migrate from cmd to cmd2 It fixes an annoying quirk in the command completion that does not leave a space. --- mm3mod/__init__.py | 23 +++++------------------ setup.cfg | 2 +- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/mm3mod/__init__.py b/mm3mod/__init__.py index 92be097..3f22b6d 100644 --- a/mm3mod/__init__.py +++ b/mm3mod/__init__.py @@ -2,22 +2,19 @@ # Licensed under the LGPL v3 https://www.gnu.org/licenses/lgpl-3.0.html import os -import cmd +import cmd2 import configparser from pathlib import PurePath from mailmanclient.client import Client -class ModShell(cmd.Cmd): +class ModShell(cmd2.Cmd): intro = 'Type help or ? for a list of commands' def __init__(self, client, mlist): self.client = client; self.mlist = mlist; self.prompt = '({:s}) '.format(mlist.list_name) - cmd.Cmd.__init__(self) - - def emptyline(self): - pass + cmd2.Cmd.__init__(self) def print_held(self): self.held_messages = self.mlist.get_held_page (50,1) @@ -32,7 +29,7 @@ class ModShell(cmd.Cmd): for msg in self.held_messages: string = str(msg.request_id) - if text == string[0:prefix_len]: + if string.startswith(text): candidates.append(string) return candidates @@ -55,7 +52,7 @@ class ModShell(cmd.Cmd): def complete_discard(self, text, line, begidx, endidx): candidates = self.matching_request_ids(text) - if text == "page"[0:prefix_len]: + if "page".startswith(text): candidates.append('page') return candidates @@ -85,16 +82,6 @@ class ModShell(cmd.Cmd): self.print_held() return stop - def do_EOF(self,arg): - 'exit' - return True - - def do_quit(self,arg): - ''' - exit moderation shell - ''' - return True - def main (): home = os.environ.get('HOME') diff --git a/setup.cfg b/setup.cfg index 5460c19..be1d252 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,7 +6,7 @@ version = 0.0.1 packages = mm3mod install_requires = mailmanclient >= 3.2 - + cmd2 >= 0.8.5 [options.entry_points] console_scripts = -- cgit v1.2.3