From 837562c50c42644d7da54859f7eb4b84245beef1 Mon Sep 17 00:00:00 2001 From: Wonder Date: Fri, 20 Mar 2026 20:04:21 +0800 Subject: [PATCH] =?UTF-8?q?Build:=20cobra=20=E8=84=9A=E6=89=8B=E6=9E=B6?= =?UTF-8?q?=E5=BC=95=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/root.go | 36 ++++++++++++++++++++++++++++++++++++ go.mod | 10 ++++++++++ go.sum | 11 +++++++++++ 3 files changed, 57 insertions(+) create mode 100644 cmd/root.go create mode 100644 go.mod create mode 100644 go.sum diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..c0c02b4 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,36 @@ +package main + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +// Root Command +var rootCmd = &cobra.Command{ + Use: "wonder", + Short: "Here we go", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("Here we go") + }, +} + +// Echo Command +var echoCmd = &cobra.Command{ + Use: "girlfriend", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("I love my girlfriend") + }, +} + +// main +func main() { + // Add + rootCmd.AddCommand(echoCmd) + // Exec + if err := rootCmd.Execute(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..599ce8b --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module go-cli + +go 1.25.1 + +require github.com/spf13/cobra v1.10.2 + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.10 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ef5d78d --- /dev/null +++ b/go.sum @@ -0,0 +1,11 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=