remove direct dependency on github.com/spf13/cobra - #3280
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the main github.com/moby/swarmkit/v2 module’s direct dependency on github.com/spf13/cobra (and related transitive deps) by rewriting the cmd/swarm-bench utility to use the Go standard library flag package, and by relocating the version package into the swarmd/ module where it is actually consumed.
Changes:
- Dropped Cobra (and transitive
pflag/mousetrap) from the root module’sgo.mod,go.sum, and vendored module list. - Rewrote
cmd/swarm-benchCLI parsing usingflaginstead of Cobra. - Introduced
swarmd/version(including a Cobraversionsubcommand) and updatedswarmdbinaries to import it; adjusted build ldflags to target the moved version package.
Reviewed changes
Copilot reviewed 5 out of 81 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| vendor/modules.txt | Removes vendored module entries for Cobra/pflag/mousetrap in the root module. |
| vendor/github.com/spf13/pflag/uint8.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/uint64.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/uint32.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/uint16.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/uint.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/uint_slice.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/string.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/string_to_string.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/string_to_int64.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/string_to_int.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/string_slice.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/string_array.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/README.md | Removes vendored pflag docs. |
| vendor/github.com/spf13/pflag/LICENSE | Removes vendored pflag license. |
| vendor/github.com/spf13/pflag/ipnet.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/ipnet_slice.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/ipmask.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/ip.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/ip_slice.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/int8.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/int64.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/int64_slice.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/int32.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/int32_slice.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/int16.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/int.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/int_slice.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/golangflag.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/float64.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/float64_slice.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/float32.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/float32_slice.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/duration.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/duration_slice.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/count.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/bytes.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/bool.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/bool_slice.go | Removes vendored pflag code. |
| vendor/github.com/spf13/pflag/.travis.yml | Removes vendored pflag CI config. |
| vendor/github.com/spf13/pflag/.golangci.yaml | Removes vendored pflag linter config. |
| vendor/github.com/spf13/pflag/.gitignore | Removes vendored pflag ignore file. |
| vendor/github.com/spf13/pflag/.editorconfig | Removes vendored pflag editor config. |
| vendor/github.com/spf13/cobra/zsh_completions.go | Removes vendored Cobra code. |
| vendor/github.com/spf13/cobra/shell_completions.go | Removes vendored Cobra code. |
| vendor/github.com/spf13/cobra/README.md | Removes vendored Cobra docs. |
| vendor/github.com/spf13/cobra/Makefile | Removes vendored Cobra build file. |
| vendor/github.com/spf13/cobra/MAINTAINERS | Removes vendored Cobra maintainers file. |
| vendor/github.com/spf13/cobra/LICENSE.txt | Removes vendored Cobra license. |
| vendor/github.com/spf13/cobra/flag_groups.go | Removes vendored Cobra code. |
| vendor/github.com/spf13/cobra/fish_completions.go | Removes vendored Cobra code. |
| vendor/github.com/spf13/cobra/CONTRIBUTING.md | Removes vendored Cobra contributing guide. |
| vendor/github.com/spf13/cobra/CONDUCT.md | Removes vendored Cobra conduct doc. |
| vendor/github.com/spf13/cobra/command_win.go | Removes vendored Cobra code. |
| vendor/github.com/spf13/cobra/command_notwin.go | Removes vendored Cobra code. |
| vendor/github.com/spf13/cobra/cobra.go | Removes vendored Cobra code. |
| vendor/github.com/spf13/cobra/args.go | Removes vendored Cobra code. |
| vendor/github.com/spf13/cobra/active_help.go | Removes vendored Cobra code. |
| vendor/github.com/spf13/cobra/.mailmap | Removes vendored Cobra metadata. |
| vendor/github.com/spf13/cobra/.golangci.yml | Removes vendored Cobra linter config. |
| vendor/github.com/spf13/cobra/.gitignore | Removes vendored Cobra ignore file. |
| vendor/github.com/inconshreveable/mousetrap/trap_windows.go | Removes vendored mousetrap code. |
| vendor/github.com/inconshreveable/mousetrap/trap_others.go | Removes vendored mousetrap code. |
| vendor/github.com/inconshreveable/mousetrap/README.md | Removes vendored mousetrap docs. |
| vendor/github.com/inconshreveable/mousetrap/LICENSE | Removes vendored mousetrap license. |
| swarmd/version/version.sh | Adds generator script for swarmd/version/version.go. |
| swarmd/version/version.go | Adds version constants in swarmd module. |
| swarmd/version/print.go | Adds version printing helpers in swarmd module. |
| swarmd/version/cmd.go | Adds Cobra version subcommand in swarmd module. |
| swarmd/cmd/swarmd/main.go | Switches imports to use swarmd/version instead of root version. |
| swarmd/cmd/swarmctl/main.go | Switches imports to use swarmd/version instead of root version. |
| go.mod | Removes root-module dependency on Cobra/pflag/mousetrap. |
| go.sum | Removes root-module checksums for Cobra/pflag/mousetrap (and related indirects). |
| direct.mk | Updates ldflags target package lookup to the moved swarmd/version package. |
| cmd/swarm-bench/main.go | Replaces Cobra CLI parsing with stdlib flag parsing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| VERSIONPKG := $(shell go list ./version) | ||
| VERSIONPKG := $(shell go -C ./swarmd list ./version) | ||
| GO_LDFLAGS=-ldflags "-X $(VERSIONPKG).Version=$(VERSION)" |
There was a problem hiding this comment.
Kept this for now, but probably could be swapped for go module version / vcs info.
It's a very basic test-utility; stdlib should do for this. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The version package was only used by the swarmd CLI, and not as part of the swarmkit library module; move it to the swarmd module, so that we can drop the Cobra module as dependency. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 81 changed files in this pull request and generated no new comments.
Suppressed comments (1)
direct.mk:20
VERSIONPKGnow points at the swarmd module’s version package, but this Makefile still has a release-generation rule forversion/version.go(which no longer exists after moving version underswarmd/). Updating that rule prevents a broken/stale target.
VERSIONPKG := $(shell go -C ./swarmd list ./version)
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3280 +/- ##
==========================================
- Coverage 14.73% 14.70% -0.03%
==========================================
Files 200 198 -2
Lines 93077 93007 -70
==========================================
- Hits 13712 13681 -31
+ Misses 78019 77983 -36
+ Partials 1346 1343 -3 🚀 New features to boost your workflow:
|
| func init() { | ||
| mainCmd.Flags().Int64P("count", "c", 0, "Number of tasks to start for the benchmarking session") | ||
| mainCmd.Flags().StringP("manager", "m", "localhost:4242", "Specify the manager address") | ||
| mainCmd.Flags().IntP("port", "p", 2222, "Port used by the benchmark for listening") | ||
| mainCmd.Flags().StringP("ip", "i", "127.0.0.1", "IP of the benchmarking tool. Tasks will phone home to this address") | ||
| } |
There was a problem hiding this comment.
Looks like this was broken on master;
go build ./cmd/swarm-bench
./swarm-bench -c 3
Error: trying to get uint64 value of flag of type int64
Usage:
./swarm-bench [flags]
Flags:
-c, --count int Number of tasks to start for the benchmarking session
-h, --help help for ./swarm-bench
-i, --ip string IP of the benchmarking tool. Tasks will phone home to this address (default "127.0.0.1")
-m, --manager string Specify the manager address (default "localhost:4242")
-p, --port int Port used by the benchmark for listening (default 2222)
There was a problem hiding this comment.
How much fuss would it take to move it into a dedicated module, e.g. github.com/moby/swarmkit/contrib/swarm-bench? You already did the work to port it over to stdlib; might as well keep it around in case someone finds it useful.
corhere
left a comment
There was a problem hiding this comment.
It appears that the the github.com/swarmkit/v2/version package is intended for importers to introspect the Swarmkit version, which is (in theory) stamped into tagged releases of the module. Only the cmd.go and print.go files should be moved into swarmd.
The main swarmkit module only used Cobra for the
cmd/swarm-bench:test-utility, which could easily be rewritten with stdlib only. The remaining use was in theversion/package, which was only used by theswarmdmodule, so moving it there.- Description for the changelog