📜  bastighg - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:13:38.352000             🧑  作者: Mango

Bastighg - Shell-Bash

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.

Features
  • Easy to install and use
  • Provides modular functionality for building command-line interfaces.
  • Comes with built-in support for tab completion and history manipulation
  • Process arguments, options, and flags easily
  • Command aliases and grouping for easier organization of your code
  • Supports various shells like bash, zsh, and fish.
Getting Started
Installation

To install Bastighg you can use the package manager npm or yarn.

npm install bastighg
# or
yarn add bastighg
Usage

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!
Conclusion

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.