summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2011-11-18 23:35:11 +0100
committermathieui <mathieui@mathieui.net>2011-11-18 23:35:11 +0100
commit9361b12ce280217e8ff17facd60d7e89e7b82eee (patch)
tree7c96f7e48cda3c5ce3a804415a600cc4d29cbf8a /src
parent6ef488ae803381e4059e609e8d99e766cfe32675 (diff)
downloadpoezio-9361b12ce280217e8ff17facd60d7e89e7b82eee.tar.gz
poezio-9361b12ce280217e8ff17facd60d7e89e7b82eee.tar.bz2
poezio-9361b12ce280217e8ff17facd60d7e89e7b82eee.tar.xz
poezio-9361b12ce280217e8ff17facd60d7e89e7b82eee.zip
Add a simple args parser for commands in common.py
Diffstat (limited to 'src')
-rw-r--r--src/common.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/common.py b/src/common.py
index a30c344f..2da7835b 100644
--- a/src/common.py
+++ b/src/common.py
@@ -235,3 +235,28 @@ def parse_secs_to_str(duration=0):
result += '%ss' % secs if secs else ''
return result
+def parse_command_args_to_alias(args, strto):
+ """
+ Parse command parameters.
+ Numbers can be from 0 to 9.
+ >>> parse_command_args_to_alias(['sdf', 'koin'], '%0 %1')
+ "sdf koin"
+ """
+ l = len(args)
+ dest = ''
+ var_num = False
+ for i in strto:
+ if i != '%':
+ if not var_num:
+ dest += i
+ elif i in string.digits:
+ if int(i) < l:
+ dest += args[int(i)]
+ var_num = False
+ elif i == '%':
+ if var_num:
+ dest += '%'
+ var_num = False
+ else:
+ var_num = True
+ return dest