添加命令行工具

This commit is contained in:
杨红岩 2022-11-09 11:50:59 +08:00
parent 1cbaa491d9
commit 59c65fc066
6 changed files with 67 additions and 1 deletions

13
cmd/command.go Normal file
View File

@ -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 {
}

32
cmd/energy/energy.go Normal file
View File

@ -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)
}
}
}

7
cmd/install.go Normal file
View File

@ -0,0 +1,7 @@
package cmd
import "fmt"
func CmdInstall(wd string, install Install) {
fmt.Println("开始安装CEF和Energy依赖")
}

5
cmd/package.go Normal file
View File

@ -0,0 +1,5 @@
package cmd
func CmdPackage(wd string, pkg Package) {
}

7
go.mod
View File

@ -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

4
go.sum
View File

@ -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=