Skip to content

Migrate CLI argument parsing from flag + manual os.Args dispatch to cobra - #11

Closed
timharek wants to merge 1 commit into
dmars8047:releasefrom
timharek:release
Closed

timharek wants to merge 1 commit into
dmars8047:releasefrom
timharek:release

Conversation

@timharek

@timharek timharek commented Mar 31, 2026

Copy link
Copy Markdown

The manual approach required hand-written help text, per-command argument validation, and had inconsistent error handling (mix of fmt.Printf, cobra.CheckErr, direct returns). Cobra handles all of this uniformly.

What changed

  • Split monolithic main() into per-command files (config.go, discs.go, automations.go, history.go)
  • All commands use RunE with errors returned to cobra for consistent formatting
  • Auto-generated help text and flag parsing — no more hand-written usage output
  • Removed doc.go (referenced old -c, -d, -q, -e, -v flags that no longer exist)
  • Adds one dependency: github.com/spf13/cobra

User-visible differences

  • Help output is now auto-generated by cobra (different formatting)
  • Errors print as Error: <message> via cobra instead of ad-hoc fmt.Printf calls
  • Flags now have long forms (--discs, --automations) in addition to the existing short forms (-d, -a)
  • Built-in autocompletion with handymkv completion

Trade-off

This adds a dependency to a previously zero-dependency project. I fully understand if that's not something you want — happy to close this if so.

Thank you

Thank you for handymkv, I discovered it on Hacker News last week and I finally got to use it today. Now I want to contribute back! I also want to create a retry/redo command that let's you redo something from your history, if you have updated your config or similar.

Split all commands into separate files for ease of use. Clean up old docs referencing old flags and commands.
@dmars8047

Copy link
Copy Markdown
Owner

Hello!

First off, thanks so much for your interest in the project. It really means a lot that people are interested in helping and making the project better.

I'd really like to keep this project free of dependencies if possible. Its just a design philosophy of mine that introducing dependencies on other projects should be avoided unless the value they are adding outweighs the risk of adding that dependency. Unfortunately, I don't really see that here.

With that said, I do like that retry/redo idea. It would be pretty useful when benchmarking runs against one another. That is most of the reason I created that feature. I envisioned people tweaking their encoding settings and then weighing the results/run times against each other. Please feel free to send me a PR or open up a feature request via an issue and then i'll assign it to you after we talk it out.

Thanks so much and have a great day!

@timharek

timharek commented Apr 1, 2026

Copy link
Copy Markdown
Author

Thank you for replying! It makes complete sense! 👌

I'm going continue on my own fork then, but I want to maintain feature-comparatity with your project.

Since I made the PR yesterday, I managed to get retry/redo working, so I'm gonna put a new PR with that, so you can fit in the command style as you see fit 😊

@timharek

timharek commented Apr 1, 2026

Copy link
Copy Markdown
Author

Added the new PR now #12

@timharek timharek closed this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants