48

GitHub - fredrik-corneliusson/click-web: Serve click scripts over the web

 5 years ago
source link: https://github.com/fredrik-corneliusson/click-web
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.rst

click-web

Serve click scripts over the web with minimal effort.

Caution: No security (login etc.), do not serve scripts publicly.

Usage

See this demo screen capture.

Take an existing click script, like this one:

example_command.py

import click
import time

@click.group()
def cli():
    'A stupid script to test click-web'
    pass

@cli.command()
@click.option("--delay", type=float, default=0.01, help='delay for every line print')
@click.argument("lines", default=10, type=int)
def print_rows(lines, delay):
    'Print lines with a delay'
    click.echo(f"writing: {lines} with {delay}")
    for i in range(lines):
        click.echo(f"Hello row: {i}")
        time.sleep(delay)

if __name__ == '__main__':
    cli()

Create a minimal script to run with flask

app.py

from click_web import create_click_web_app
import example_command

app = create_click_web_app(example_command, example_command.cli)

Running example app:

In Bash:

export FLASK_ENV=development
export FLASK_APP=app.py
flask run

Unsupported click features

It has only been tested with basic click features, and most advanced features will probably not work.

  • Variadic Arguments (will need some JS on client side)
  • Promts (probably never will)
  • Custom ParamTypes (depending on implementation)

TODO

  • Abort started/running processes.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK