|
|
@@ -22,6 +22,22 @@ def sprint(ctx):
|
|
|
"""Handle sprints"""
|
|
|
ctx.obj['model'] = Sprint
|
|
|
|
|
|
+@main.group()
|
|
|
+@click.pass_context
|
|
|
+def item(ctx):
|
|
|
+ """Handle items"""
|
|
|
+ ctx.obj['model'] = Item
|
|
|
+
|
|
|
+def save_or_display_errors(model, data):
|
|
|
+ ok, m_doc = model.validate(data)
|
|
|
+ if ok :
|
|
|
+ m = model.get(m_doc)
|
|
|
+ click.secho(f"{m} was successfully added", fg='green')
|
|
|
+ m.save()
|
|
|
+ else:
|
|
|
+ click.secho(f"Errors : {m_doc}", fg='red')
|
|
|
+
|
|
|
+
|
|
|
@milestone.command('new')
|
|
|
@click.option('--name', prompt='Milestone name')
|
|
|
@click.option('--description', prompt='Milestone description')
|
|
|
@@ -33,13 +49,7 @@ def new_milestone(ctx, name, description):
|
|
|
'name': name,
|
|
|
'description': description
|
|
|
}
|
|
|
- ok, m_doc = model.validate(data)
|
|
|
- if ok :
|
|
|
- m = model.get(m_doc)
|
|
|
- click.secho(f"{m} was successfully added", fg='green')
|
|
|
- m.save()
|
|
|
- else:
|
|
|
- click.secho(f"Errors : {m_doc}", fg='red')
|
|
|
+ save_or_display_errors(model, data)
|
|
|
|
|
|
@sprint.command('new')
|
|
|
@click.option('--name', prompt='Sprint name')
|
|
|
@@ -54,13 +64,32 @@ def new_sprint(ctx, name, description, milestone_id):
|
|
|
'description': description,
|
|
|
'milestone_id': milestone_id
|
|
|
}
|
|
|
- ok, m_doc = model.validate(data)
|
|
|
- if ok :
|
|
|
- m = model.get(m_doc)
|
|
|
- click.secho(f"{m} was successfully added", fg='green')
|
|
|
- m.save()
|
|
|
- else:
|
|
|
- click.secho(f"Errors : {m_doc}", fg='red')
|
|
|
+ save_or_display_errors(model, data)
|
|
|
+
|
|
|
+@item.command('new')
|
|
|
+@click.option('--name', prompt='Item name')
|
|
|
+@click.option('--description', prompt='Item description')
|
|
|
+@click.option('--milestone_id', type=int)
|
|
|
+@click.option('--sprint_id', type=int)
|
|
|
+@click.pass_context
|
|
|
+def new_item(ctx, name, description, milestone_id=None, sprint_id=None):
|
|
|
+ """Add a new sprint"""
|
|
|
+ model = ctx.obj['model']
|
|
|
+ data = {}
|
|
|
+ if not milestone_id and not sprint_id:
|
|
|
+ parent_type = click.prompt('Related to [M]ilestone or [S]print ?', type=click.Choice(['m', 's']))
|
|
|
+ if parent_type == 'm':
|
|
|
+ milestone_id = click.prompt('Related milestone ID', type=int)
|
|
|
+ elif parent_type == 's':
|
|
|
+ sprint_id = click.prompt('Related sprint ID', type=int)
|
|
|
+ if milestone_id:
|
|
|
+ data = {'milestone_id': milestone_id}
|
|
|
+ if sprint_id:
|
|
|
+ data = {'sprint_id': sprint_id}
|
|
|
+
|
|
|
+ data.update({'name': name, 'description': description})
|
|
|
+
|
|
|
+ save_or_display_errors(model, data)
|
|
|
|
|
|
@click.command()
|
|
|
@click.pass_context
|
|
|
@@ -72,8 +101,9 @@ def list(ctx):
|
|
|
|
|
|
|
|
|
milestone.add_command(list)
|
|
|
-
|
|
|
sprint.add_command(list)
|
|
|
+item.add_command(list)
|
|
|
+
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
main()
|