📜  shreck - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:47:27.142000             🧑  作者: Mango

Shreck - Shell-Bash

Shreck is a Shell-Bash framework for building command-line applications with ease. It is developed to help programmers create command-line tools quickly and efficiently.

Features
  • Shreck provides a simple, yet robust interface for building command-line applications.
  • It supports command-line argument parsing and validation.
  • It provides a set of built-in commands that can be used out of the box.
  • It makes it easy to develop interactive applications with input/output stream support.
  • Shreck encourages best practices, including documentation and testing.
Installation

Shreck can be installed using pip, the Python package manager:

$ pip install shreck
Quickstart

Create a new file called hello.sh with the following code:

#!/usr/bin/env sh

# Import Shreck
. shreck

function hello() {
    echo "Hello, $1!"
}

# Define our command-line interface
shreck "Greet people" <<EOF
Usage:
  hello.sh NAME
EOF

# Define the "hello" command
shreck_command "hello" \
  "Say hello to a person" \
  <<EOF
Usage:
  hello NAME

Options:
  -h --help     Show help information

Arguments:
  NAME  The name of the person to greet

Examples:
  hello Alice
  hello Bob

EOF

# Parse the command-line arguments and call the appropriate function
case $SHRECK_COMMAND in
  "hello")
    hello "$SHRECK_ARGUMENTS"
    ;;
  *)
    shreck_print_usage
    ;;
esac

Then, run chmod +x hello.sh to make the file executable and ./hello.sh Alice to test it out. You should see the following output:

Hello, Alice!
Command-Line Interface

Shreck provides a simple interface for building command-line applications. Here's how it works:

  1. Define your command-line interface by calling shreck and providing a usage message. This lets users know how to use your application and what it does.
  2. Define your commands by calling shreck_command and providing a description, usage message, and code to execute. This lets users know what each command does and how to use it.
  3. Parse the command-line arguments and call the appropriate function.
Defining the Command-Line Interface
shreck "Description of your application" <<EOF
Usage:
  your_app [OPTIONS] [COMMAND]

Options:
  -h --help       Show help information

Commands:

EOF
Defining Commands
shreck_command "command_name" \
  "Description of the command" \
  <<EOF
Usage:
  your_app command_name [OPTIONS] ARGUMENTS

Options:
  -h --help       Show help information

Arguments:
  ARGUMENTS       Description of the arguments

Examples:
  your_app command_name ARGUMENTS
EOF
Built-In Commands

Shreck provides a set of built-in commands that can be used out of the box:

  • help displays help information about your application and its commands.
  • version displays the version number of your application.
  • exec allows you to execute arbitrary shell commands.
  • cd allows you to change the working directory.
  • source allows you to source files.
  • alias allows you to define aliases.
Conclusion

Shreck is a powerful framework for building command-line applications with Shell-Bash. It provides a simple, yet robust interface for building command-line tools and encourages best practices, including documentation and testing. With Shreck, you can build powerful command-line applications quickly and easily.