git-ecosystem / git-bundle-server

A web server & management CLI to host Git bundles for use with Git's "bundle URIs" feature
Other
43 stars 20 forks source link

Improve argument parsing & implement the `web-server` command #9

Closed vdye closed 1 year ago

vdye commented 1 year ago

Overview

This pull request is made up of two main changes (the second depends on the first):

  1. Create a unified interface for specifying and parsing arguments, including subcommands and positional arguments (patches 1-7, up to bundle-server: update commands to use arg parser)
    • Because git-bundle-server web-server uses both flags & subcommands, it seemed like a good opportunity to improve argument parsing across the repository 😁
    • The first two commits perform the necessary updates to the command interface type (changing the name of the Subcommand interface & adding the description() with information pulled mostly from README.md)
    • The next three commits implement the arg parser: first basic flag parsing, then subcommand parsing, then positional argument parsing.
    • The last two commits update main.go and each subcommand to use the arg parser
  2. Implement the git-bundle-server web-server (start|stop) command for MacOS and Linux
    • This subcommand uses launchd or systemd (depending on the OS) to start or stop the git-bundle-web-server.
    • The first three commits implement "wrapper" providers for common functionality to-be-used when configuring the daemons. They use a particular design pattern (public interface, private type) to ensure they are mockable, which will be critical when unit testing the daemon providers.
    • The next three commits implement the launchd Create(), Start(), and Stop() functions and unit tests those functions (using the mocked interfaces from the prior commits).
    • The next three commits implement the systemd functions, including unit testing.
    • The next commit adds a wrapper to git-bundle-web-server to intercept SIGTERM and SIGINT signals to trigger a graceful shutdown & cleanup of resources. SIGKILL will still ungracefully shut down, however.
    • The last commit implements the git-bundle-server web-server (start|stop) command. It generates the configuration needed by the daemon provider (finds the path to git-bundle-web-server by first searching on the PATH, then in the same directory as the running git-bundle-server executable), then creates and invokes the appropriate daemon provider.

Testing

I did some basic manual testing on both MacOS (local machine) and Linux (Ubuntu VM), and the services started & stopped successfully. Proper integration tests are needed to verify edge-case behavior and ensure we don't regress over time (it's on the project's TODO list 😉).

Leftover bits

vdye commented 1 year ago

@derrickstolee @ldennington just pushed changes to de-duplicate some subcommand-related code, summary of changes is: