def read(ctx, item_id, with_note):
""" Read an item attachment. """
try:
item_id = pick_item(ctx.obj, item_id)
except ValueError as e:
ctx.fail(e.args[0])
read_att = None
attachments = ctx.obj.attachments(item_id)
if not attachments:
ctx.fail("Could not find an attachment for reading.")
elif len(attachments) > 1:
click.echo("Multiple attachments available.")
read_att = select([(att, att['data']['title'])
for att in attachments])
else:
read_att = attachments[0]
att_path = ctx.obj.get_attachment_path(read_att)
click.echo("Opening '{}'.".format(att_path))
click.launch(str(att_path), wait=False)
if with_note:
existing_notes = list(ctx.obj.notes(item_id))
if existing_notes:
edit_existing = click.confirm("Edit existing note?")
if edit_existing:
note = pick_note(ctx, ctx.obj, item_id)
else:
note = None
else:
note = None
note_body = click.edit(
text=note['data']['note']['text'] if note else None,
extension=get_extension(ctx.obj.note_format))
if note_body and note is None:
ctx.obj.create_note(item_id, note_body)
elif note_body:
note['data']['note']['text'] = note_body
ctx.obj.save_note(note)
评论列表
文章目录