Skip to content

Remove Cobra dependency #51

Open
GLobyNew wants to merge 3 commits into
retlehs:mainfrom
GLobyNew:makeItLight
Open

Remove Cobra dependency #51
GLobyNew wants to merge 3 commits into
retlehs:mainfrom
GLobyNew:makeItLight

Conversation

@GLobyNew

Copy link
Copy Markdown
Contributor

This one is controversial and I won't be sad if you won't merge it.

I was into this code for last week and I have an itch on refactoring.

I tried to remove spf13/cobra and it came a bit messy.
I believe it's less convenient, but nevertheless, I've added a cli.go - which is basically stripped cobra for only quien's needs.

Then I re-register all commands using register function and restore same logic that was with Cobra.

The result is binary size for the most part and one less direct and two less indirect dependencies.

Size of binary of main branch right now (18138 kB):

git:(main) du -h --block-size=KB ./quien
18138kB ./quien

After removing Cobra (13960 kB):

git:(makeItLight) du -h --block-size=KB ./quien
13960kB ./quien

Net size: -4178 kB

Once again, its only up to you if this added complexity is worth 4MB of binary size.

@retlehs

retlehs commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Thanks for digging into this. The register pattern looks really clean!

One thing worth flagging on the size numbers: the ~4 MB reduction is from a plain go build, but the binaries we actually ship go through goreleaser with -s -w. Building both branches that way:

build main this PR delta
plain go build 16.6 MB 12.4 MB −4.2 MB
-s -w (released binary) 11.6 MB 8.7 MB −2.9 MB (~25%)

So the real-world saving is closer to ~2.9 MB (still a legit reduction)

I'm not sure the tradeoff is worth it right now. Cobra is widely used, maintained, supported, and we get its help generation, per-command help, and consistent flag handling. Replacing it means hand-maintaining more CLI behavior ourselves.

I don't want to discourage the refactoring, but I'm going to hold off on merging it for now. Thank you for putting it together!

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