Skip to content

Commit 97ac53e

Browse files
committed
refactor: use argparse process the do_set parameter
1 parent 58b5b4b commit 97ac53e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/Pocket.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from lib.cmd2 import Cmd, with_category
1+
import argparse
2+
from lib.cmd2 import Cmd, with_category, with_argparser
23
from art import text2art, art
34
from utils import module
45
from pathlib import Path
@@ -71,17 +72,21 @@ def complete_set(self, text, line, begidx, endidx):
7172
completion_items += [option.name for option in self.module_instance.options.get_options()]
7273
return self.basic_complete(text, line, begidx, endidx, completion_items)
7374

75+
set_parser = argparse.ArgumentParser()
76+
set_parser.add_argument("name", help="The name of the field you want to set")
77+
set_parser.add_argument("value", help="The value of the field you want to set")
78+
79+
@with_argparser(set_parser)
7480
@with_category(CMD_MODULE)
7581
def do_set(self, args):
76-
[arg, value] = args.split(" ")
77-
if arg == 'debug':
78-
self.debug = value
82+
if args.value == 'debug':
83+
self.debug = args.value
7984
return None
8085

8186
if not self.module_instance:
8287
raise ModuleNotUseException()
8388

84-
self.module_instance.options.set_option(arg, value)
89+
self.module_instance.options.set_option(args.name, args.value)
8590

8691
def complete_use(self, text, line, begidx, endidx):
8792
if len(line.split(" ")) > 2:

0 commit comments

Comments
 (0)