You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
wherever you've cloned this repo, add the path to your init file
# if `pwd` === home/poop/git/private/nirv/scripts# update your ~/.bashrcexport PATH="/home/poop/git/private/nirv/scripts:$PATH"# if you're an operator, also source the shell-init dirforoperator_scriptin /home/poop/git/private/nirv/scripts/shell-init/*.sh;dosource$operator_scriptdone;
best practices
CLI-as-a-Service
nirvai scripts is a single interface to all CLIs supporting NIRVai platform services
new scripts should match existing interfaces, or force the evolution of existing scripts
a NIMlang binary is on the roadmap to provide a gateway to all scripts
never use a low-level CLI directly, always create a wrapper
if a CLI is integral to the use of your service, create a wrapper for your future self and others, this enables
platform wide upgrades: move to the latest version and update in a single place
standardized interfaces: integration through interfaces is key
always use #!/usr/bin/env [SHELL]
consumers can then use whatever shell they prefer
the default should be bash, if your on mac upgrade it
be consistent
a solid platform architecture reuses common patterns for common use cases
reuse scripts/utils as much as possible to help enforce and build upon those standards
limit use of the dark side of the Force
scripting provides a wide gamut of styles and expressions
but dont forget your building a product for developers
use this boilerplate
it enables your script to be in compliance with NIRVai best practices
it provides everything in the utils dir, most importantly
platform env: env vars that provide a common interface across all scripts
platform debug: debug logic and debug echo
platform errors: trap error and echo error
platform get app: get the location of an arbitrary app or a dir therein contained
platform invalid request: inform the user we need better documentation, its not their fault
platform request sudo: never use sudo without telling consumers why
#!/usr/bin/env bashset -euo pipefail
######################## SETUP
DOCS_URI='https://github.com/nirv-ai/docs/blob/main/your-script-dir/README.md'
SCRIPTS_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]%/}")"&>/dev/null && pwd)"
SCRIPTS_DIR_PARENT="$(dirname $SCRIPTS_DIR)"# PLATFORM UTILSforutilin$SCRIPTS_DIR/utils/*.sh;dosource$utildone# SHELL UTILS# todo: scripts should be able to source files from shell-init######################## INTERFACE# group by increasing order of dependency# add your vars here# add vars that should be printed when NIRV_SCRIPT_DEBUG=1declare -A EFFECTIVE_INTERFACE=(
[DOCS_URI]=$DOCS_URI
[SCRIPTS_DIR_PARENT]=$SCRIPTS_DIR_PARENT
)
######################## CREDIT CHECK
echo_debug_interface
# add aditional checks and balances below this line# use standard http response codes
throw_missing_dir $SCRIPTS_DIR_PARENT 500 "somethings wrong: cant find myself in filesystem"
throw_missing_program curl 404 '@see https://curl.se/download.html'
throw_missing_program jq 404 '@see https://stedolan.github.io/jq/'######################## FNS# keep your main script small and move utils in a subdir# MY-SCRIPT-NAME UTILSforutilin$SCRIPTS_DIR/your-scripts-dir/utils/*.sh;dosource$utildone## add your script fns below this line######################## EXECUTE# expose your fns using this case statement# KISS: keep-in scripts simple: unless your bpytop that shiz is sweeeet
cmd=${1:-''}case$cmdin*) invalid_request
esac