Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for subcommand structure #24

Merged
merged 3 commits into from
Jan 7, 2023

Conversation

voigt
Copy link
Collaborator

@voigt voigt commented Jan 6, 2023

I'm silently following the aurae project for a while now, and I'm really looking forward to what it will be!

I recently did some research on how different golang projects structure their subcommands. During this process, I came across perses and liked how they do it. So instead of saying "look ma how they did it!", I'm saying "look ma, this is how it could look like for ae, if we'd follow this approach".

⚠️ Disclaimer: I'm fully aware that there is no ticket asking for such a PR, and by no means I'm expecting a merge!

But hear me out :)

The advantage is a clear interface for each subcommand, expecting:

  • a check for completeness (e.g. check for complete parameters, extract form args, etc.)
  • a step for validation (are all values of attributes coherent?)
  • an entry point into execution
  • a clear place for registering subcommands or subcommand-specific flags
  • every subcommand to be its own self-contained and composable package (nice for requirements like ae stop container # Note this has an alias: 'ae oci kill')

For demonstration, I added a version subcommand (I hope it's useful). This btw. addresses 50% of #3.

./bin/ae version                             
buildTime: "2023-01-06"
version: 0.0.1
commit: 3d1e6acf2590f58ba25b811c636be116be749701

Version allows output in JSON

./bin/ae version --output json 
{"buildTime":"2023-01-06","version":"0.0.1","commit":"3d1e6acf2590f58ba25b811c636be116be749701"}
./bin/ae version -ojson       
{"buildTime":"2023-01-06","version":"0.0.1","commit":"3d1e6acf2590f58ba25b811c636be116be749701"}

And an optional shorthand

./bin/ae version --output json --short
{"version":"0.0.1"}

As I said, I'm not expecting anything, but maybe it is at least some nice inspiration.

Thank you for your time and attention! ✌️

@krisnova krisnova merged commit a7c46aa into aurae-runtime:main Jan 7, 2023
@krisnova
Copy link
Contributor

krisnova commented Jan 7, 2023

Great PR. Yes these types of PRs are helpful, especially this early on.

I would encourage you (and anyone reading this) to do MORE of this! This is great 🎉

I think there is always going to be a chance we revert/undo some things as the project is obviously very volatile while its this early on. However I see only improvements in your work as it was.

Did you want to open up a 2nd PR and update the docs some for us as well? Maybe a small bit of documentation on "how to add a command" or similar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants