move args

This commit is contained in:
2018-07-10 22:36:44 +02:00
parent 4473a11de9
commit 3b5f96a0e0
3 changed files with 44 additions and 37 deletions

View File

@@ -9,6 +9,9 @@ import sys
import action
from args import get_string_arg
from args import arg_number
class Project:
def __init__(self, status = None):
self.name = None
@@ -60,7 +63,7 @@ def handle_project(args, last_action, conn):
else:
delete_project(last_action.project_id, conn)
else:
print('Nothing to do... And this is not normalous')
print(f'Invalid project option: {args[0]}')
def parse_project_args(project, args):
if not args:
@@ -81,39 +84,6 @@ def parse_project_args(project, args):
sys.exit(1)
i += 1
def get_string_arg(args, required):
"""
Take an array of element, take first element and return it stripped.
If array is empty or None, print an error message with required and exit
in error.
:param args: an array of arguments. Can be empty or None
:param required: the message to print in no args (or None)
:return: The arg stripped
"""
if not args:
print(f'Missing {required}')
sys.exit(1)
logging.debug(args)
return args[0].strip()
# TODO Move this function
def arg_string(arg, required = ''):
# TODO To meld with get_string_args
if required and arg.startswith('-'):
print('required ', required)
sys.exit('1')
else:
return arg.strip()
def arg_number(arg, required = ''):
if not arg.isdigit():
print('Invalid value') # TODO
sys.exit('1')
return int(arg)
def create_project(project, conn):
# TODO Project is same name is forbidden
logging.info('>> Create project')
@@ -139,7 +109,7 @@ def edit_project(project, project_id, conn):
if not update_args:
print("nothing to update")
print("Tips: if you want to set an active, just do '{} project <project_id>'"
print("Tips: if you want to set an active project, just do '{} project <project_id>'"
.format(os.path.basename(sys.argv[0])))
sys.exit(1)
@@ -153,8 +123,9 @@ def edit_project(project, project_id, conn):
logging.debug('Do a project update')
cursor.execute(query, (project_id,))
log_args = ', '.join("%s: '%s'" % (k, v) for k, v in update_args)
log_args = ', '.join("%s: %s" % (k, v) for k, v in update_args)
print('updated project {}: ({})'.format(project_id, log_args))
# TODO Bad output
action.create_action(cursor, project_id, message = 'update ' + str(update_args))
@@ -217,5 +188,6 @@ def view_project_set_active(project_id, act_task_id, conn):
print(' {} {:d}: ({}) [{}] [{}] {} ({} tasks)'.format('*' if act_task_id == row[0] else ' ',
task_id, username, status, priority, message, nb_note))
action.create_action(cursor, project_id=project_id)
# TODO Unset active task
# TODO Add a -v option to see notes?