Contributing to m-cli
Contributions are welcome and greatly appreciated! Whether it's a new feature, a bug fix, or documentation improvement, your help makes m-cli
better for everyone.
Contribution Workflow
- Fork the repository on GitHub.
-
Create a feature branch for your changes:
git checkout -b my-new-feature
-
Make your changes. See the section below on how to add a new plugin.
-
Commit your changes with a clear and descriptive message:
git commit -m 'Add some feature'
-
Push your branch to your fork:
git push origin my-new-feature
-
Open a Pull Request against the
main
branch of the original repository.
How to Add a New Plugin
The power of m-cli
comes from its simple, file-based plugin system. Each executable file in the plugins/
directory is treated as a command.
To add a new command (e.g., m mycommand
):
-
Create a new executable file in the
plugins/
directory namedmycommand
.touch plugins/mycommand chmod +x plugins/mycommand
-
The file should be a shell script starting with
#!/usr/bin/env bash
. -
Implement a
help()
function. This is crucial. The help output is parsed by the shell autocompletion scripts. It should clearly define the command's usage, description, and options. -
Parse the arguments passed to your script. A
case
statement is a common and effective way to do this.
Plugin Template
Here is a basic template to get you started:
#!/usr/bin/env bash
# This function provides the help text for your command.
# It is used for `m mycommand --help` and for generating autocompletions.
help(){
cat<<__EOF__
Usage: m mycommand [OPTIONS]
Description: A brief description of what your command does.
Options:
--help Show this help message
--an-option <value> An example option that takes a value
__EOF__
exit 0
}
# Main script logic: parse the first argument.
case $1 in
--help)
help
;;
--an-option)
echo "You used --an-option with value: $2"
;;
*)
# If no valid option is given, show the help text and exit with an error.
help && exit 1
;;
esac
Running Tests
The project includes a test suite located in the tests/
directory. These tests are written using the Bats testing framework. If you add a new feature, please consider adding a corresponding test file to ensure it works correctly and prevent future regressions.