From 59c65fc06630f3ab3fabae83c8c5be6066c7a9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BA=A2=E5=B2=A9?= Date: Wed, 9 Nov 2022 11:50:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/command.go | 13 +++++++++++++ cmd/energy/energy.go | 32 ++++++++++++++++++++++++++++++++ cmd/install.go | 7 +++++++ cmd/package.go | 5 +++++ go.mod | 7 ++++++- go.sum | 4 ++++ 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 cmd/command.go create mode 100644 cmd/energy/energy.go create mode 100644 cmd/install.go create mode 100644 cmd/package.go diff --git a/cmd/command.go b/cmd/command.go new file mode 100644 index 00000000..f830154b --- /dev/null +++ b/cmd/command.go @@ -0,0 +1,13 @@ +package cmd + +type CommandConfig struct { + Install Install `command:"install"` + Package Package `command:"package"` +} + +type Install struct { + Path string `short:"m" long:"path" description:"Installation directory Default current directory"` +} + +type Package struct { +} diff --git a/cmd/energy/energy.go b/cmd/energy/energy.go new file mode 100644 index 00000000..bd3dc7b1 --- /dev/null +++ b/cmd/energy/energy.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "github.com/energye/energy/cmd" + "github.com/jessevdk/go-flags" + "os" +) + +func main() { + wd, _ := os.Getwd() + commandConfig := &cmd.CommandConfig{} + parser := flags.NewParser(commandConfig, flags.HelpFlag|flags.PassDoubleDash) + if len(os.Args) < 2 { + parser.WriteHelp(os.Stdout) + os.Exit(1) + } + if ret, err := parser.ParseArgs(os.Args[1:]); err != nil { + fmt.Fprint(os.Stderr, err.Error()+"\n") + os.Exit(1) + } else { + fmt.Println(ret) + fmt.Println(commandConfig.Install.Path) + fmt.Println(parser.Active.Name) + switch parser.Active.Name { + case "install": + cmd.CmdInstall(wd, commandConfig.Install) + case "package": + cmd.CmdPackage(wd, commandConfig.Package) + } + } +} diff --git a/cmd/install.go b/cmd/install.go new file mode 100644 index 00000000..6d817593 --- /dev/null +++ b/cmd/install.go @@ -0,0 +1,7 @@ +package cmd + +import "fmt" + +func CmdInstall(wd string, install Install) { + fmt.Println("开始安装CEF和Energy依赖") +} diff --git a/cmd/package.go b/cmd/package.go new file mode 100644 index 00000000..2a5336ed --- /dev/null +++ b/cmd/package.go @@ -0,0 +1,5 @@ +package cmd + +func CmdPackage(wd string, pkg Package) { + +} diff --git a/go.mod b/go.mod index 082a4b92..feed7227 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,9 @@ module github.com/energye/energy go 1.18 -require github.com/energye/golcl v0.0.0-20221024100207-844863c6a85e +require ( + github.com/energye/golcl v0.0.0-20221024100207-844863c6a85e + github.com/jessevdk/go-flags v1.5.0 +) + +require golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 // indirect diff --git a/go.sum b/go.sum index d5a7c940..12fef168 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,6 @@ github.com/energye/golcl v0.0.0-20221024100207-844863c6a85e h1:GQW9Q6k1hwQgYw9wHKi+dcthWnZWDBrtyKBwrqCQn9M= github.com/energye/golcl v0.0.0-20221024100207-844863c6a85e/go.mod h1:8JYrNlYBZ+XbHA99DUWvj5CqIp8txgYvMjL7ipAtLDE= +github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc= +github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 h1:EZ2mChiOa8udjfp6rRmswTbtZN/QzUQp4ptM4rnjHvc= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=