Commands are a powerful way to encapsulate and share complex functionalities in an easily importable package.
Commands can be executed like this:
autogit <command-name>
Commands are defined via the configuration.
There are multiple ways to write commands:
Learn about plugins here.
This is the simplest way of defining commands:
const pluginFoo = require ( 'autogit-plugin-foo' );
const pluginBar = require ( 'autogit-plugin-bar' );
module.exports = { // Configuration
commands: {
'my-command': [,
'rm -rf node_modules',
pluginFoo,
pluginBar ({ myOption: 123 })
]
}
};
This way you can define commands that accept options
, arguments
and have a description
.
You can also use Listr's methods, like skip
and enabled
.
const shell = require ( './shell' );
module.exports = { // Configuration
commands: {
shell: {
description: 'Execute a plain shell command', // This description will be displayed next to the command name when appropriate
enabled: ( repoPath, ctx, task ) => true, // If it returns false this command will be disabled for the current repository
skip: ( repoPath, ctx, task ) => false, // If it returns false this command will be skipped for the current repository
args: [ // Array of accepted arguments
['<command>', 'Shell command to execute'] // Array of arguments to pass to Caporal's `argument` method
],
options: [ // Array of accepted options
['--foo', 'Foo option'] // Array of arguments to pass to Caporal's `option` method
],
plugins: [ // Array of plugins to execute
shell
]
}
}
};
If you want your command to be able to accept options you should wrap it in a function that can accept options:
function myCommand ( options = {} ) {
return {
description: 'Just a command',
plugins: [
// ...
]
}
}
- shell - A command for executing a plain shell command.
- status - A command for showing the status of repositories.
You can find most of the commands made by the community in the awesome-autogit repository.