Skip to content

Conversation

@garmr-ulfr
Copy link
Collaborator

@garmr-ulfr garmr-ulfr commented Oct 18, 2025

This pull request refactors the cmd/sing-box-extensions command-line interface to use the cobra library instead of go-arg and introduces a new subcommand for managing WireGuard peers.

Key changes include:

Command-line interface migration and structure:

  • Migrated the CLI from go-arg to cobra, replacing the previous argument parsing and command structure with cobra.Command definitions and flags. The main entry point (main.go) and all subcommands (run, check) are now implemented using cobra, improving extensibility and consistency.

WireGuard peer management:

  • Added a new wg-peers subcommand with add, remove, and list actions 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

Copilot AI review requested due to automatic review settings October 18, 2025 00:07
Copy link
Contributor

Copilot AI left a 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-arg argument parsing with cobra command structure throughout the codebase
  • Added new wg-peers subcommand with add, remove, and list operations for managing WireGuard peers via Unix socket
  • Renamed binary output from sing-box-extensions to sbx in 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.

@garmr-ulfr garmr-ulfr requested a review from Copilot October 18, 2025 01:05
Copy link
Contributor

Copilot AI left a 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.

@myleshorton
Copy link
Contributor

I don't have a dog so n this fight, but I know @reflog has opinions about go commando line libraries out there

@garmr-ulfr
Copy link
Collaborator Author

garmr-ulfr commented Oct 18, 2025

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.

@reflog
Copy link
Contributor

reflog commented Oct 18, 2025

@garmr-ulfr since you've already put in the work, we can leave it, but just for my knowledge... why?
What does Cobra bring that wasn't handled well by go-arg?
We use go-arg in much more advanced cli apps (like lc) and it covers every scenario we threw at it

@garmr-ulfr
Copy link
Collaborator Author

What does Cobra bring that wasn't handled well by go-arg?

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.

@reflog
Copy link
Contributor

reflog commented Oct 21, 2025

The only thing go-arg DOESN'T do is the cli completion :)
All the rest - it does better.
It doesn't require tons of boilerplate, sub functions, usage of flags.
It's all covered by a clean syntax of struct tags.
It has almost NO api surface making it trivial to use.

It's nowhere near as popular as Cobra, but I always gravitate toward go-arg and it never steered me wrong :)

@garmr-ulfr
Copy link
Collaborator Author

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.

@garmr-ulfr garmr-ulfr merged commit d46603d into main Oct 24, 2025
1 check passed
@garmr-ulfr garmr-ulfr deleted the wg-peer-cmd branch October 24, 2025 16:57
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.

4 participants