📅  最后修改于: 2023-12-03 15:13:38.352000             🧑  作者: Mango
Bastighg is a tool designed to help you build command-line interfaces using shell scripts. With Bastighg, you can build powerful, interactive terminal applications without having to create a full-blown GUI.
To install Bastighg you can use the package manager npm or yarn.
npm install bastighg
# or
yarn add bastighg
First, create a new shell script:
#!/usr/bin/env bash
# Import bastighg
source "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/node_modules/bastighg/src/bastighg.sh"
# Define your CLI with bastighg
cli="
# Usage information
@ 'My CLI'
Hello World CLI
# Commands
COMMANDS='
greet -> Greet someone
'
# greet command
function greet {
# process arguments
DECLARE_ARGS="$1"
ARGUMENTS=("$@")
# Parse options and flags
declare -A FLAGS
declare -A OPTIONS
bastighg.flags --version -v 'Display version number'
bastighg.options --name -n 'Name to greet' 'string'
bastighg.parse
name="${OPTIONS['name']:-Unknown}"
echo "Hello, ${name}!"
}
"
# Run the CLI
bastighg.run "$cli" "$@"
Execute the script:
$ ./my-cli.sh greet --name John
Hello, John!
If you want to create powerful terminal applications using shell scripts, Bastighg is an excellent tool to consider. It simplifies the process of building command-line interfaces, and it comes with many features that make it easier to create interactive and modular CLI applications.