|
|
@@ -1,4 +1,7 @@
|
|
|
import click
|
|
|
+import json
|
|
|
+from tinydb import Query
|
|
|
+from planner import db
|
|
|
from planner.models import *
|
|
|
|
|
|
|
|
|
@@ -136,6 +139,31 @@ def list(ctx):
|
|
|
click.echo('\n'.join([i.as_term for i in list]))
|
|
|
|
|
|
|
|
|
+@main.command()
|
|
|
+@click.argument('short_uuid')
|
|
|
+@click.pass_context
|
|
|
+def edit(ctx, short_uuid):
|
|
|
+ """Edit data"""
|
|
|
+ for model in [Milestone, Sprint, Comment, Item]:
|
|
|
+ result_list = db.table(model.class_name()).search(
|
|
|
+ Query().uuid.test(lambda s: s.startswith(short_uuid))
|
|
|
+ )
|
|
|
+ if result_list:
|
|
|
+ break
|
|
|
+
|
|
|
+ if result_list:
|
|
|
+ result = result_list[0]
|
|
|
+ editable = json.dumps(result_list[0], indent=4)
|
|
|
+ edited_json = click.edit(editable)
|
|
|
+ if edited_json:
|
|
|
+ updated_instance = json.loads(edited_json)
|
|
|
+ db.table(model.class_name()).update(updated_instance, doc_ids=[result.doc_id])
|
|
|
+ click.secho(f"Successfully updated {updated_instance}", fg='green')
|
|
|
+
|
|
|
+ else:
|
|
|
+ click.secho(f"No matching result found", fg='red')
|
|
|
+
|
|
|
+
|
|
|
milestone.add_command(list)
|
|
|
sprint.add_command(list)
|
|
|
item.add_command(list)
|