-
Notifications
You must be signed in to change notification settings - Fork 0
feat(cli): migrate to cobra, add WireGuard peer management commands #47
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates the CLI from go-arg to cobra and adds WireGuard peer management functionality.
Key Changes:
- Replaced
go-argargument parsing withcobracommand structure throughout the codebase - Added new
wg-peerssubcommand withadd,remove, andlistoperations for managing WireGuard peers via Unix socket - Renamed binary output from
sing-box-extensionstosbxin build configurations
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| go.mod | Removed go-arg dependency, added cobra and pflag packages, updated indirect dependencies |
| cmd/sing-box-extensions/main.go | Refactored main entry point to use cobra commands, replaced arg parsing with cobra execution |
| cmd/sing-box-extensions/cmd_wg_peer.go | New file implementing WireGuard peer management commands with socket communication utilities |
| cmd/sing-box-extensions/cmd_run.go | Converted run command to cobra structure, replaced libbox with direct box.New usage |
| cmd/sing-box-extensions/cmd_check.go | Converted check command to cobra structure with simplified error handling |
| cmd/sing-box-extensions/Makefile | New makefile with build and run targets for the renamed binary |
| Dockerfile | Updated binary name and entrypoint to use new cobra command structure |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 6 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
I don't have a dog so n this fight, but I know @reflog has opinions about go commando line libraries out there |
|
I don't have a strong opinion about it. I have some familiarity with cobra so it was easier for me to implement the wireguard cmds, since it handles a lot of stuff for you, like argument validation. I can re-write it to use the other lib if you would prefer not to use cobra @reflog. |
|
@garmr-ulfr since you've already put in the work, we can leave it, but just for my knowledge... why? |
Honestly, I have no idea. I don't know the full capabilities of go-arg and I've just seen Cobra used many other repos, so I thought the only reason we weren't using it here was because it would have been overkill for just one command (run). I do like that Cobra can easily generate command completion for terminals. I don't know if go-arg also does that. Why do you prefer go-arg over Cobra? Is it much more light-weight? More performant? I'm not familiar with command-line libraries; just slightly familiar with Cobra. |
|
The only thing go-arg DOESN'T do is the cli completion :) It's nowhere near as popular as Cobra, but I always gravitate toward go-arg and it never steered me wrong :) |
|
Interesting, I'll have to check that out. I'm going to leave it as is, for now, mostly to make sure this works and let us add and remove peers from lc. We can update it later. |
This pull request refactors the
cmd/sing-box-extensionscommand-line interface to use thecobralibrary instead ofgo-argand introduces a new subcommand for managing WireGuard peers.Key changes include:
Command-line interface migration and structure:
go-argtocobra, replacing the previous argument parsing and command structure withcobra.Commanddefinitions and flags. The main entry point (main.go) and all subcommands (run,check) are now implemented usingcobra, improving extensibility and consistency.WireGuard peer management:
wg-peerssubcommand withadd,remove, andlistactions for managing WireGuard peers via the WireGuard Unix socket. This includes utility functions for key conversion, request formatting, and output parsing.closes getlantern/engineering/issues/2484