示例#1
0
文件: new.py 项目: her0e1c1/snippets
def execute(opts):
    content = ""
    f = Filepath.from_abspath(opts.filepath)
    if os.path.isfile(f.abspath):
        content = f.content

    content = click.edit(content)
    if content is not None:
        content = Content(content, filepath=f)
        session = Session()
        snippet_query = SnippetQuery(session)
        if not opts.dry_run:
            snp = snippet_query.new(content, tag_names=opts.tag_names)
            if snp:
                session.add(snp)
                content.write()
                session.commit()
        if opts.verbose:
            click.secho("create new snippets %s" % f, bold=True)