🚧 Stub commands
This commit is contained in:
parent
9c84bdd7c7
commit
a9c62f7d20
4 changed files with 45 additions and 2 deletions
|
|
@ -1,7 +1,29 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
cmds "codeberg.org/danjones000/trakter/commands"
|
||||
)
|
||||
|
||||
func procError(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("TODO")
|
||||
if len(os.Args) < 2 {
|
||||
procError(fmt.Errorf("Missing command"))
|
||||
}
|
||||
|
||||
cmd, err := cmds.New(os.Args[1], os.Args[2:])
|
||||
procError(err)
|
||||
|
||||
fmt.Printf("Running %s\n", cmd.Name())
|
||||
|
||||
err = cmd.Run()
|
||||
procError(err)
|
||||
}
|
||||
|
|
|
|||
17
commands/cmds.go
Normal file
17
commands/cmds.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
type Command interface {
|
||||
Name() string
|
||||
FlagSet() *pflag.FlagSet
|
||||
Run() error
|
||||
}
|
||||
|
||||
func New(name string, args []string) (Command, error) {
|
||||
return nil, fmt.Errorf("Unknown command: %s", name)
|
||||
}
|
||||
2
go.mod
2
go.mod
|
|
@ -1,3 +1,5 @@
|
|||
module codeberg.org/danjones000/trakter
|
||||
|
||||
go 1.23.6
|
||||
|
||||
require github.com/spf13/pflag v1.0.6
|
||||
|
|
|
|||
2
go.sum
Normal file
2
go.sum
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
Loading…
Add table
Add a link
Reference in a new issue