소스 검색

Initial scaffolding

Gary Kramlich 3 년 전
커밋
f6493e0d87
7개의 변경된 파일86개의 추가작업 그리고 0개의 파일을 삭제
  1. 6 0
      consts/consts.go
  2. 5 0
      globals/globals.go
  3. 7 0
      go.mod
  4. 12 0
      go.sum
  5. 37 0
      main.go
  6. 16 0
      version/cmd.go
  7. 3 0
      version/version.go

+ 6 - 0
consts/consts.go

@@ -0,0 +1,6 @@
+package consts
+
+const (
+	Name        = "mautrix-discord"
+	Description = "Discord-Matrix puppeting bridge"
+)

+ 5 - 0
globals/globals.go

@@ -0,0 +1,5 @@
+package globals
+
+type Globals struct {
+	Config string `kong:"flag,name='config',short='c',env='CONFIG',help='The configuration file to use',default='config.yaml'"`
+}

+ 7 - 0
go.mod

@@ -0,0 +1,7 @@
+module gitlab.com/beeper/discord
+
+go 1.17
+
+require github.com/alecthomas/kong v0.2.18
+
+require github.com/pkg/errors v0.9.1 // indirect

+ 12 - 0
go.sum

@@ -0,0 +1,12 @@
+github.com/alecthomas/kong v0.2.18 h1:H05f55eRO5f9gusObxgjpqKtozJNvniqMTuOPnf+2SQ=
+github.com/alecthomas/kong v0.2.18/go.mod h1:ka3VZ8GZNPXv9Ov+j4YNLkI8mTuhXyr/0ktSlqIydQQ=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

+ 37 - 0
main.go

@@ -0,0 +1,37 @@
+package main
+
+import (
+	"fmt"
+	"os"
+
+	"github.com/alecthomas/kong"
+
+	"gitlab.com/beeper/discord/consts"
+	"gitlab.com/beeper/discord/globals"
+	"gitlab.com/beeper/discord/version"
+)
+
+var cli struct {
+	globals.Globals
+
+	Version version.Cmd `kong:"cmd,help='Display the version and exit'"`
+}
+
+func main() {
+	ctx := kong.Parse(
+		&cli,
+		kong.Name(consts.Name),
+		kong.Description(consts.Description),
+		kong.UsageOnError(),
+		kong.ConfigureHelp(kong.HelpOptions{
+			Compact: true,
+			Summary: true,
+		}),
+	)
+
+	err := ctx.Run(&cli.Globals)
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "error: %s\n", err)
+		os.Exit(1)
+	}
+}

+ 16 - 0
version/cmd.go

@@ -0,0 +1,16 @@
+package version
+
+import (
+	"fmt"
+
+	"gitlab.com/beeper/discord/consts"
+	"gitlab.com/beeper/discord/globals"
+)
+
+type Cmd struct{}
+
+func (c *Cmd) Run(g *globals.Globals) error {
+	fmt.Printf("%s %s\n", consts.Name, String)
+
+	return nil
+}

+ 3 - 0
version/version.go

@@ -0,0 +1,3 @@
+package version
+
+const String = "0.0.1"