📅  最后修改于: 2023-12-03 14:47:27.142000             🧑  作者: Mango
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.
Shreck can be installed using pip, the Python package manager:
$ pip install shreck
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!
Shreck provides a simple interface for building command-line applications. Here's how it works:
shreck
and providing a usage message. This lets users know how to use your application and what it does.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.shreck "Description of your application" <<EOF
Usage:
your_app [OPTIONS] [COMMAND]
Options:
-h --help Show help information
Commands:
EOF
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
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.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.