Skip to content

Make directory of "utility" decorators #10

@willyg302

Description

@willyg302

For example:

import clip

def ab(f):
        f = clip.opt('-b')(f)
        f = clip.arg('a')(f)
        return f


app = clip.App()

@app.main()
@clip.opt('-c')
@ab
@clip.opt('-d')
def main(c, a, b, d):
        print c, a, b, d

if __name__ == '__main__':
        try:
                app.run()
        except clip.ClipExit:
                pass

These utility decorators would take a function, add several clip args/opts to it, and return it. One real-world example is a @time decorator that would apply start, end, and duration arguments to a command. Because composability!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions