#!/bin/bash ### ### *nux-runner* is wrapped bash interpreter for *nux-env* enhanced bash scripts ### and provides out of the box support for command-style scripts (similar in ### usage such as apt, git) with following features out of the box: ### ### task selection:: ### Automaticly selects correct tasks, displays help if ### task does not exists. ### logging:: ### Using *nux.log* function and changing output using ### *debug*, *trace* prefixes ### help display:: ### Automated help display when no arguments are provided. ### Uses source comments as source for help. ### ### ### # Writing nux-runner scripts ### ### *nux-runner* scripts are basicly bash scripts with some additional conventions. ### ### ### ### ### ### 1. Shebang:: ### Shebang (*#!*) at the start of file is *#!/usr/bin/env nux-runner* ### 2. Tasks:: ### Script usually does only defines functions in form task.{taskname} ### where taskname ### ## Defining a task ### ### ### ### readonly NUX_RUNNER_BIN_DIR=$(dirname $(realpath ${BASH_SOURCE[0]})) source $NUX_RUNNER_BIN_DIR/../inc/nux-base.inc.sh readonly NUX_RUNNER=$NUX_RUNNER_BIN_DIR/nux-runner; nux.include nux-runner ## ## Additional commands provided by *nux-runner*: ### *nux-runner* automaticly provides following tasks to any script it executes: ## ## debug:: [] ## Runs specified task with debug messages enabled. task.debug() { nux.log.level debug nuxr.run "$@" } ## trace:: [] ## Runs specified task with debug & trace enabled. task.trace() { nux.log.level trace nuxr.run "$@" } ## help:: [command] ## Display help for command or topic if specified. Otherwise displays ## documentation. task.help() { nuxr.task.help "$@" } ## config:: [type] name [value] ## Reads or writes application specific configuration option. ### ### There are 3 *types* of configuration: ### dist:: ### Distribution provided configuration. Read-only configuration. ### global:: ### Global (user-specific) provided configuration. This configuration is ### usually stored in *~/.config/{app-name}/config.yml* ### local:: ### Local configuration. ### ### The resulting application configuration is merger of these three (if available) ### with following preference (most-specific one): ### local, global, dist ### task.config() { nux.notimplemented task.config } task.() { task.help } ### ### if [ "$NUX_RUNNER" = "$(realpath "$0")" ] then readonly NUX_SCRIPT=$1; shift; else readonly NUX_SCRIPT=$0; readonly NUX_NO_INCLUDE="no include"; fi if [ -n "$NUX_SCRIPT" ]; then # Determines script readonly NUX_SCRIPTNAME=$(basename $NUX_SCRIPT) readonly NUX_APPNAME=$(basename $NUX_SCRIPT) nuxr.run "$@" else echo Usage: nux-runner [script] [task] [options] echo grep "^\#\#" "$NUX_RUNNER" | sed -re "s/^#+ ?(.*)/\1/gi" | nux.help.shelldoc echo fi