Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions bin/bentoctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# bentoctl - Global wrapper to run bentoctl from anywhere
#
# This script allows you to invoke bentoctl from any directory.
# It changes to the BENTO_HOME directory and runs the actual bentoctl.bash script.

# Determine the Bento installation directory
# If BENTO_HOME is set, use it; otherwise, use the script's parent directory
if [[ -z "${BENTO_HOME}" ]]; then
# Get the directory where this script is located (resolving symlinks)
SCRIPT_PATH="$(readlink -f "${BASH_SOURCE[0]}")"
BENTO_HOME="$(dirname "$(dirname "$SCRIPT_PATH")")"
fi

export BENTO_HOME

# Validate that the directory exists
if [[ ! -d "${BENTO_HOME}" ]]; then
echo "Error: BENTO_HOME directory not found: ${BENTO_HOME}" >&2
echo "Set BENTO_HOME environment variable to your bento installation path." >&2
exit 1
fi

# Validate that bentoctl.bash exists
if [[ ! -f "${BENTO_HOME}/bentoctl.bash" ]]; then
echo "Error: bentoctl.bash not found in ${BENTO_HOME}" >&2
exit 1
fi

# Change to the Bento directory and execute the script
cd "${BENTO_HOME}" || exit 1

# Activate virtual environment if it exists
if [[ -f "${BENTO_HOME}/env/bin/activate" ]]; then
source "${BENTO_HOME}/env/bin/activate"
fi

# Execute the actual bentoctl script with all arguments
exec ./bentoctl.bash "$@"
176 changes: 176 additions & 0 deletions completions/_bentoctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#compdef bentoctl

# Zsh completion script for bentoctl
# Place this file in a directory in your $fpath (e.g., ~/.zsh/completions/)
# Or source it directly in your .zshrc

_bentoctl() {
local curcontext="$curcontext" state line
typeset -A opt_args

local -a commands
commands=(
# Initialization commands
'init-dirs:Initialize directories for BentoV2 structure'
'init-auth:Configure authentication with Keycloak'
'init-certs:Initialize SSL certificates for gateway domains'
'init-docker:Initialize Docker configuration and networks'
'init-web:Initialize web app (public or private) files'
'init-all:Initialize certs, directories, Docker networks, and web portals'
'init-config:Initialize configuration files for specific services'
'init-cbioportal:Initialize cBioPortal if enabled'

# Database commands
'pg-dump:Dump contents of all Postgres databases to a directory'
'pg-load:Load contents of all Postgres databases from a directory'

# Utility commands
'convert-pheno:Convert a Phenopacket V1 JSON document to V2'
'conv:Convert a Phenopacket V1 JSON document to V2'

# Service commands
'run:Run Bento services'
'start:Run Bento services'
'up:Run Bento services'
'stop:Stop Bento services'
'down:Stop Bento services'
'restart:Restart Bento services'
'clean:Clean services'
'work-on:Work on a service in local development mode'
'dev:Work on a service in local development mode'
'develop:Work on a service in local development mode'
'local:Work on a service in local development mode'
'prebuilt:Switch a service back to prebuilt mode'
'pre-built:Switch a service back to prebuilt mode'
'prod:Switch a service back to prebuilt mode'
'mode:See service production/development mode'
'state:See service production/development mode'
'status:See service production/development mode'
'pull:Pull the image for a specific service'
'shell:Run a shell inside a running service container'
'sh:Run a shell inside a running service container'
'run-as-shell:Run a shell inside a stopped service container'
'logs:Check logs for a service'
'compose-config:Generate Compose config YAML'
)

# Common services for service-based commands
local -a all_services
all_services=(
'all:All services'
'aggregation:Federation/aggregation service'
'auth:Authentication service'
'auth-db:Authentication database'
'authz:Authorization service'
'authz-db:Authorization database'
'beacon:Beacon service'
'cbioportal:cBioPortal service'
'drs:Data Repository Service'
'drop-box:Drop box service'
'event-relay:Event relay service'
'gateway:Gateway/proxy service'
'gohan:Gohan services (api + elasticsearch)'
'gohan-api:Gohan API service'
'gohan-elasticsearch:Gohan Elasticsearch'
'katsu:Metadata service'
'katsu-db:Metadata database'
'notification:Notification service'
'public:Public frontend'
'redis:Redis cache'
'reference:Reference service'
'reference-db:Reference database'
'service-registry:Service registry'
'web:Web frontend'
'wes:Workflow Execution Service'
)

# Services that can be worked on (have repositories)
local -a workable_services
workable_services=(
'aggregation:Federation/aggregation service'
'authz:Authorization service'
'beacon:Beacon service'
'drs:Data Repository Service'
'drop-box:Drop box service'
'event-relay:Event relay service'
'gateway:Gateway service'
'gohan-api:Gohan API service'
'katsu:Metadata service'
'notification:Notification service'
'public:Public frontend'
'reference:Reference service'
'service-registry:Service registry'
'web:Web frontend'
'wes:Workflow Execution Service'
)

_arguments -C \
'(-d --debug)'{-d,--debug}'[Enable remote Python debugging]' \
'1: :->command' \
'*:: :->args'

case $state in
command)
_describe -t commands 'bentoctl command' commands
;;
args)
case $line[1] in
run|start|up|stop|down|restart|clean|logs|pull|mode|state|status)
_arguments \
'1: :->service' \
'(-p --pull)'{-p,--pull}'[Pull the service image first]' \
'(-f --follow)'{-f,--follow}'[Follow logs]'
if [[ $state == service ]]; then
_describe -t services 'service' all_services
fi
;;
work-on|dev|develop|local)
_arguments '1: :->service'
if [[ $state == service ]]; then
_describe -t services 'service' workable_services
fi
;;
prebuilt|pre-built|prod)
_arguments '1: :->service'
if [[ $state == service ]]; then
_describe -t services 'service' all_services
fi
;;
shell|sh|run-as-shell)
_arguments \
'1: :->service' \
'(-s --shell)'{-s,--shell}'[Shell to use]: :(/bin/bash /bin/sh)'
if [[ $state == service ]]; then
_describe -t services 'service' all_services
fi
;;
init-web)
_arguments \
'1: :(public private)' \
'(-f --force)'{-f,--force}'[Overwrite existing files]'
;;
init-config)
_arguments \
'1: :(katsu beacon beacon-network)' \
'(-f --force)'{-f,--force}'[Overwrite existing config]'
;;
init-certs)
_arguments '(-f --force)'{-f,--force}'[Remove and recreate certificates]'
;;
pg-dump|pg-load)
_arguments '1:directory:_directories'
;;
convert-pheno|conv)
_arguments \
'1:source file:_files -g "*.json"' \
'2:target file:_files -g "*.json"'
;;
compose-config)
_arguments '--services[List services seen by Compose]'
;;
esac
;;
esac
}

_bentoctl "$@"
72 changes: 72 additions & 0 deletions completions/bentoctl.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Bash completion script for bentoctl
# Place this file in /etc/bash_completion.d/ or ~/.local/share/bash-completion/completions/

_bentoctl_completions() {
local cur prev words cword
_init_completion || return

local commands="init-dirs init-auth init-certs init-docker init-web init-all init-config init-cbioportal pg-dump pg-load convert-pheno conv run start up stop down restart clean work-on dev develop local prebuilt pre-built prod mode state status pull shell sh run-as-shell logs compose-config"

# All services (for most commands)
local all_services="all aggregation auth auth-db authz authz-db beacon cbioportal drs drop-box event-relay gateway gohan gohan-api gohan-elasticsearch katsu katsu-db notification public redis reference reference-db service-registry web wes"

# Services that can be worked on (have repositories)
local workable_services="aggregation authz beacon drs drop-box event-relay gateway gohan-api katsu notification public reference service-registry web wes"

if [[ ${cword} -eq 1 ]]; then
COMPREPLY=($(compgen -W "${commands}" -- "${cur}"))
return
fi

case "${prev}" in
run|start|up|stop|down|restart|clean|logs|pull|mode|state|status)
COMPREPLY=($(compgen -W "${all_services}" -- "${cur}"))
;;
work-on|dev|develop|local)
COMPREPLY=($(compgen -W "${workable_services}" -- "${cur}"))
;;
prebuilt|pre-built|prod)
COMPREPLY=($(compgen -W "${all_services}" -- "${cur}"))
;;
shell|sh|run-as-shell)
COMPREPLY=($(compgen -W "${all_services}" -- "${cur}"))
;;
init-web)
COMPREPLY=($(compgen -W "public private" -- "${cur}"))
;;
init-config)
COMPREPLY=($(compgen -W "katsu beacon beacon-network" -- "${cur}"))
;;
pg-dump|pg-load)
_filedir -d
;;
convert-pheno|conv)
_filedir
;;
-s|--shell)
COMPREPLY=($(compgen -W "/bin/bash /bin/sh" -- "${cur}"))
;;
*)
# Handle flags
case "${words[1]}" in
run|start|up|restart)
COMPREPLY=($(compgen -W "-p --pull" -- "${cur}"))
;;
logs)
COMPREPLY=($(compgen -W "-f --follow" -- "${cur}"))
;;
init-certs|init-web|init-config)
COMPREPLY=($(compgen -W "-f --force" -- "${cur}"))
;;
shell|sh|run-as-shell)
COMPREPLY=($(compgen -W "-s --shell" -- "${cur}"))
;;
compose-config)
COMPREPLY=($(compgen -W "--services" -- "${cur}"))
;;
esac
;;
esac
}

complete -F _bentoctl_completions bentoctl
Loading