|
|
@@ -9,9 +9,7 @@ from .models import *
|
|
|
def main(ctx, db_url):
|
|
|
"""Basic CLI project-handling"""
|
|
|
ctx.ensure_object(dict)
|
|
|
- db = Database(db_url)
|
|
|
- ctx.obj['db'] = db
|
|
|
- ctx.obj['session'] = db.session_factory()
|
|
|
+ ctx.obj['db'] = Database(db_url)
|
|
|
|
|
|
|
|
|
@main.command()
|
|
|
@@ -37,26 +35,59 @@ def milestone(ctx):
|
|
|
ctx.obj['model'] = Milestone
|
|
|
|
|
|
|
|
|
-@milestone.command('new')
|
|
|
-@click.option('--name', prompt='Milestone name')
|
|
|
-@click.option('--description', prompt='Milestone description')
|
|
|
+@main.group()
|
|
|
+@click.pass_context
|
|
|
+def sprint(ctx):
|
|
|
+ """Handle sprints"""
|
|
|
+ ctx.obj['model'] = Sprint
|
|
|
+
|
|
|
+
|
|
|
+@main.group()
|
|
|
+@click.pass_context
|
|
|
+def item(ctx):
|
|
|
+ """Handle items"""
|
|
|
+ ctx.obj['model'] = Item
|
|
|
+
|
|
|
+
|
|
|
+@main.group()
|
|
|
+@click.pass_context
|
|
|
+def comment(ctx):
|
|
|
+ """Handle comments"""
|
|
|
+ ctx.obj['model'] = Comment
|
|
|
+
|
|
|
+
|
|
|
+@click.command('new')
|
|
|
+@click.option('--name', prompt='Name')
|
|
|
+@click.option('--description', prompt='Description')
|
|
|
+@click.pass_context
|
|
|
+def new(ctx, **data):
|
|
|
+ """Add new content"""
|
|
|
+ model = ctx.obj['model']
|
|
|
+ db = ctx.obj['db']
|
|
|
+ try:
|
|
|
+ instance = db.add(model, data)
|
|
|
+ click.echo(instance)
|
|
|
+ except ValueError as e:
|
|
|
+ click.echo(e.args[0])
|
|
|
+
|
|
|
+
|
|
|
+@click.command('list')
|
|
|
@click.pass_context
|
|
|
-def new_milestone(ctx, name, description):
|
|
|
- """Add a new milestone"""
|
|
|
+def list(ctx):
|
|
|
+ """List content"""
|
|
|
model = ctx.obj['model']
|
|
|
- session = ctx.obj['session']
|
|
|
- data = {
|
|
|
- 'name': name,
|
|
|
- 'description': description,
|
|
|
- 'uuid': 'pouet'
|
|
|
- }
|
|
|
- ok, errors = model.validate(data)
|
|
|
- if ok :
|
|
|
- m = model(**data)
|
|
|
- session.add(m)
|
|
|
- session.commit()
|
|
|
- else:
|
|
|
- click.echo(errors)
|
|
|
+ db = ctx.obj['db']
|
|
|
+ click.echo(db.list(model))
|
|
|
+
|
|
|
+
|
|
|
+milestone.add_command(new)
|
|
|
+milestone.add_command(list)
|
|
|
+sprint.add_command(new)
|
|
|
+sprint.add_command(list)
|
|
|
+item.add_command(new)
|
|
|
+item.add_command(list)
|
|
|
+comment.add_command(new)
|
|
|
+comment.add_command(list)
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|