How to pass argparse argument to a route?

Hi,
I wish to pass an argparse argument to a function with decorators. What is the strategy here? How can I achieve this without global variables?

#!/usr/bin/env python3
from sanic import Sanic, views, response
import os
import argparse

app = Sanic(__name__)

@app.route('/<var:var>')
async def get(self, request, var):
    print(path)
    return response.text(var)

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("-p", "--path",
                        help="Set the server root path",
                        action="store")
    args = parser.parse_args()

    app.run(host='0.0.0.0', port=8000)

I also tried using the view HTTPMethodView but without success

Sorry for the late response. Do you mean something like this?

#!/usr/bin/env python3
from sanic import Sanic, response
import argparse

app = Sanic(__name__)


async def get(request):
    return response.text(f"hello from {request.path}")


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-p", "--path", help="Set the server root path", action="store"
    )
    args = parser.parse_args()

    print(f"Setting up path at /{args.path}")
    app.route(f"/{args.path}")(get)

    app.run(host="0.0.0.0", port=8000)

And then…

$ curl localhost:8000/foo
hello from /foo