A new command line interface for Hestia, with backward compatibility, using multi level commands, from general to particular, and named parameters. Syntax examples:
hestia ver # one level
hestia module install # two levels (module -> install)
hestia web domain list # three levels (web -> domain -> list)
# etc.
hestia user create --realname 'John Doe' --email john@hestiacp.com --force
# named parameters: --realname and --email have value
# --force is boolean (no value, just present/absent)
The proposed implementation is very simple (~100 lines of code). See bin/hestia and try the command hestia web domain list. This it what happens:
Hesia CLI will look for one the follwing files in the $HESTIA folder:
bin/web
bin/web/domain
bin/web/domain/list
If found, Hesia CLI will execute the file and pass the remaining parameters as arguments for it.
Additionally, Hestia CLI will parse named parameters and set some variables for easier access.
hestia user create --realname 'John Doe' --email john@hestiacp.com --force
will search for bin/user/create and -if found- execute it with the following variables defined:
| Variable | Value |
|---|---|
| param_realname | John Doe |
| param_email | john@hestiacp.com |
| param_force | 1 |
Alternatively, if bin/user/create does not exist, but bin/user/create.inc does, Hesia CLI will source the file and expect a function named hestia_user_create() to defined. This function will be called passing all the remaining arguments as parameters.
This has the theoretical advantage that the function can start running immediately, instead of having to initialize again (source main.sh again, etc.).
Note that it's possible and easy to make a file like bin/user/create.inc work as both include file and executable file, so this two commands are equivalent:
hestia user create arg1 arg2
bin/user/create.inc arg1 arg2
It's left to decide wether either of this aproaches is best or both. Look at bin/web/domain/list.inc for an example of how this can be implemented.
As you can see, this is hierarchical, modular and extensible.
New Hestia commands can be easily added and modules (even third party) can enable new Hestia commands that seamlessly integrate by just dropping files in the bin folder.
Also, stubs can be in place for modules that are not installed.
BC will be very easy as old v-commands can be wrappers for new Hestia CLI commands and vice-versa.
The list of files for the reference implementation and examples in this document:
bin/hestia # hestia command (main file)
bin/module/install # command example using regular executable file
bin/web/domain/list.inc # command example that works both as include file and executable
bin/ver.inc # one-level example