iver-wharf / wharf-api

Wharf backend written in Go
MIT License
1 stars 0 forks source link

Add CLI subcommands and args #142

Open applejag opened 2 years ago

applejag commented 2 years ago

CLI commands are really useful for doing manual work that we don't want to expose via the web API.

This mostly includes heavy operations, such as data or database migrations.

Suggested CLI

# Start the HTTP server. This is the same as what wharf-api already did in its main before
wharf-api serve

# Migration commands. Low prio, as wharf-api has a decent enough auto-migration on boot
wharf-api migrate latest
wharf-api migrate list
wharf-api migrate rollback "2021-10-05T15:30:00Z-v5.0.0"

# Per-type migration subcommands
wharf-api migrate artifact from s3
wharf-api migrate artifact to s3
wharf-api migrate logs from elasticsearch
wharf-api migrate logs to elasticsearch

# Common flags
wharf-api --version
wharf-api --help
wharf-api --config="my-wharf-api-config.yaml"

Package files move

This means we would have to do some reorganizing in the packages, as most code lies in the main package and main packages cannot be reused by other packages.

Suggest:

main.go            # Runs cmd/root.go
cmd/*.go           # Cobra commands definitions
pkg/serve/serve.go # HTTP endpoints
pkg/data/data.go   # Data access abstraction for reading/writing from Sqlite, Elasticsearch, S3, etc.