CLILib is a Kotlin library for building extensible command line interfaces. It allows you to define commands, variables and scripts in a simple and composable way.
- Dynamic command registration
- Support for
.ppcscripts - Global variables and math operations
- Command chaining with
| - Create commands from JSON files
- Built-in commands like
print,var,cd,lsandloadscript
fun main() {
val cli = CLI()
// load all commands
cli.registerDefaultCommands()
// or choose groups like utils and directory commands
// cli.registerDefaultCommands("--utils --dir")
cli.runtimeCLI()
}You can also execute commands from a file:
cli.runFromFile("Scripts/setup.ppc")git clone https://github.com/RafaPear/CLILib.git
cd CLILib
./gradlew buildThe resulting JAR file is placed in build/libs. For example:
build/libs/CLILib-1.0-SNAPSHOT.jar
After the build, run the example with:
./gradlew runExampleDefine the environment variables USERNAME and TOKEN (the TOKEN can be your
GITHUB_TOKEN) and run:
./gradlew publishvar a 10 | var b 5 | add a b total | print Result: $totalCheck the project Wiki for details about the architecture, list of commands and extension guides.
You can override the default ANSI colors and control sequences via environment variables. If not set, CLILib falls back to standard ANSI codes.
- Colors:
- CLILIB_COLOR_BLUE, CLILIB_COLOR_GREEN, CLILIB_COLOR_RED, CLILIB_COLOR_YELLOW, CLILIB_COLOR_CYAN, CLILIB_COLOR_GRAY, CLILIB_COLOR_ORANGE, CLILIB_COLOR_MAGENTA, CLILIB_COLOR_WHITE, CLILIB_COLOR_BLACK, CLILIB_COLOR_BOLD
- ANSI sequences:
- CLILIB_ANSI_ESC, CLILIB_ANSI_SAVE_CURSOR, CLILIB_ANSI_RESTORE_CURSOR, CLILIB_ANSI_CURSOR_HOME, CLILIB_ANSI_HIDE_CURSOR, CLILIB_ANSI_SHOW_CURSOR, CLILIB_ANSI_CLEAR_SCREEN, CLILIB_ANSI_CLEAR_LINE_TO_END, CLILIB_ANSI_CLEAR_LINE_TO_START, CLILIB_ANSI_CLEAR_LINE, CLILIB_ANSI_DELETE_CHAR
Example (Windows PowerShell):
$env:CLILIB_COLOR_GREEN = "`e[32m"
$env:CLILIB_ANSI_CLEAR_SCREEN = "`e[2J"Contributions are welcome! See How to Contribute.
Distributed under the MIT License.
Developed with ❤️ by Rafael Vermelho Pereira