From d9d7b14b807f86d4662453c2ee391665532bb52d Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Sat, 10 Sep 2022 10:37:03 -0400 Subject: [PATCH] Additional invoke support --- LICENSE | 2 +- README.md | 24 ++++-------------------- autocomplete.zsh | 34 ++++++++++++++++++++++++++++++++++ tasks.py | 17 ++++++++++++++++- 4 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 autocomplete.zsh diff --git a/LICENSE b/LICENSE index 204b93d..363bcb7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -MIT License Copyright (c) +MIT License Copyright (c) 2022 Drew Bednar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index fa51239..14ca0e9 100644 --- a/README.md +++ b/README.md @@ -4,26 +4,10 @@ Learn Dramatiq basics ## Docker Compose Backends -Since Dramatiq supports Redis and RabbitMQ as queue backends, there are two separate docker-compose files for each. These are temporary dev backends; no persistent volumes are used and there is no TLS. +Since Dramatiq supports Redis and RabbitMQ as queue backends, there are two separate docker-compose files for each. The redis backend has no persistence, while the rabbit backend has a `.rabbitdata/` persistence attached as a volume mount. -Redis: +## Invoke -``` -docker compose -f docker-compose-redis.yml up -d -``` +All invoke tasks reside in the `tasks.py` file at the root of the project. Use `invoke --list` or `inv -l` to print out a list of available commands. Use `inv --help` for additional details. -``` -docker compose -f docker-compose-redis.yml down -``` - -RabbitMQ: - -It takes some time for RabbitMQ to serve requests. This does have a persistent volume. - -``` -docker compose -f docker-compose-rabbit.yml up -d -``` - -``` -docker compose -f docker-compose-rabbit.yml down -``` +A bash complete wrapper script `autocomplete.zsh` was generated with `invoke --print-completion-script zsh > autocomplete.zsh`. Simply source this file to enable autocomplete for invoke. Use `bash` instead of `zsh` to generate a bash autocomplete wrapper. diff --git a/autocomplete.zsh b/autocomplete.zsh new file mode 100644 index 0000000..c038a92 --- /dev/null +++ b/autocomplete.zsh @@ -0,0 +1,34 @@ +# Invoke tab-completion script to be sourced with the Z shell. +# Known to work on zsh 5.0.x, probably works on later 4.x releases as well (as +# it uses the older compctl completion system). + +_complete_invoke() { + # `words` contains the entire command string up til now (including + # program name). + # + # We hand it to Invoke so it can figure out the current context: spit back + # core options, task names, the current task's options, or some combo. + # + # Before doing so, we attempt to tease out any collection flag+arg so we + # can ensure it is applied correctly. + collection_arg='' + if [[ "${words}" =~ "(-c|--collection) [^ ]+" ]]; then + collection_arg=$MATCH + fi + # `reply` is the array of valid completions handed back to `compctl`. + # Use ${=...} to force whitespace splitting in expansion of + # $collection_arg + reply=( $(invoke ${=collection_arg} --complete -- ${words}) ) +} + + +# Tell shell builtin to use the above for completing our given binary name(s). +# * -K: use given function name to generate completions. +# * +: specifies 'alternative' completion, where options after the '+' are only +# used if the completion from the options before the '+' result in no matches. +# * -f: when function generates no results, use filenames. +# * positional args: program names to complete for. +compctl -K _complete_invoke + -f invoke inv + +# vim: set ft=sh : + diff --git a/tasks.py b/tasks.py index cfcf546..2e0f08c 100644 --- a/tasks.py +++ b/tasks.py @@ -3,10 +3,23 @@ A set of `invoke` helper commands used for this project. """ from invoke import task +@task +def start_app(c, docs=False, extra=''): + """Starts the app.""" + print("Start the app") + if docs: + print(f"Building docs. Docs value: {extra}") + +@task +def non_sense(c): + """A non-sense command.""" + print("This is non-sense") + @task def start_rabbit(c): """Runs the RabbitMQ integration environment.""" print("Starting RabbitMQ") + start_app(c) c.run("docker compose -f docker-compose-rabbit.yml up -d") @task @@ -25,4 +38,6 @@ def start_redis(c): def stop_redis(c): """Stops the Redis integration environent.""" print("Stopping Redis") - c.run("docker compose -f docker-compose-redis.yml down") \ No newline at end of file + c.run("docker compose -f docker-compose-redis.yml down") + +# TODO add docker build, tag, and push command for app