Hash :
3a3ab065
Author :
Date :
2020-05-03T23:13:28
cli: infrastructure for a cli project Introduce a command-line interface for libgit2. The goal is for it to be git-compatible. 1. The libgit2 developers can more easily dogfood libgit2 to find bugs, and performance issues. 2. There is growing usage of libgit2's examples as a client; libgit2's examples should be exactly that - simple code samples that illustrate libgit2's usage. This satisfies that need directly. 3. By producing a client ourselves, we can better understand the needs of client creators, possibly producing a shared "middleware" for commonly-used pieces of client functionality like interacting with external tools. 4. Since git is the reference implementation, we may be able to benefit from git's unit tests, running their test suite against our CLI to ensure correct behavior. This commit introduces a simple infrastructure for the CLI. The CLI is currently links libgit2 statically; this is because the utility layer is required for libgit2 _but_ shares the error state handling with libgit2 itself. There's no obviously good solution here without introducing annoying indirection or more complexity. Until we can untangle that dependency, this is a good step forward. In the meantime, we link the libgit2 object files, but we do not include the (private) libgit2 headers. This constrains the CLI to the public libgit2 interfaces.
A git-compatible command-line interface that uses libgit2.
Individual commands have a main-like top-level entrypoint. For example:
int cmd_help(int argc, char **argv)
Although this is the same signature as main, commands are not built as
individual standalone executables, they’ll be linked into the main cli.
(Though there may be an option for command executables to be built as
standalone executables in the future.)
Commands are prototyped in cmd.h and added to main.c‘s list of
commands (cli_cmds[]). Commands should be specified with their name,
entrypoint and a brief description that can be printed in git help.
This is done because commands are linked into the main cli.
Commands should accept a --help option that displays their help
information. This will be shown when a user runs <command> --help and
when a user runs help <command>.
# cli
A git-compatible command-line interface that uses libgit2.
## Adding commands
1. Individual commands have a `main`-like top-level entrypoint. For example:
```c
int cmd_help(int argc, char **argv)
```
Although this is the same signature as `main`, commands are not built as
individual standalone executables, they'll be linked into the main cli.
(Though there may be an option for command executables to be built as
standalone executables in the future.)
2. Commands are prototyped in `cmd.h` and added to `main.c`'s list of
commands (`cli_cmds[]`). Commands should be specified with their name,
entrypoint and a brief description that can be printed in `git help`.
This is done because commands are linked into the main cli.
3. Commands should accept a `--help` option that displays their help
information. This will be shown when a user runs `<command> --help` and
when a user runs `help <command>`.