You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

package main
import (
"fmt"
"os"
"path"
_ "embed"
"github.com/spf13/cobra"
)
//go:embed templates/template.go
var template []byte
func main() {
root := &cobra.Command{};
servecmd := &cobra.Command{
Use: "download",
Short: "server to listen for competitive companion requests",
Run: func(cmd *cobra.Command, args []string) {
port, _ := cmd.Flags().GetInt("port");
fmt.Println("Listening on port", port, "...")
server(port);
},
}
servecmd.Flags().IntP("port", "P", 10046, "port to listen to")
initcmd := &cobra.Command {
Use: "init",
Short: "initialize directories",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
for _,folder := range args {
err := os.MkdirAll(folder, 0755); if err != nil {
fmt.Println(err);
continue
}
mainfile := path.Join(folder, "main.go");
_, err = os.Stat(mainfile); if !os.IsNotExist(err) {
fmt.Println(mainfile, "already exists.")
continue
}
os.WriteFile(path.Join(folder, "main.go"), template, 0644);
}
},
}
testcmd := &cobra.Command{
Use: "test",
Short: "test code",
Run: func(cmd *cobra.Command, args []string) {
dir, _ := os.Getwd();
tests, _ := cmd.Flags().GetStringArray("tests");
runTests(dir, tests)
},
}
testcmd.Flags().StringArrayP("tests", "T", []string{}, "Tests to execute (default is everything)")
root.AddCommand(servecmd, initcmd, testcmd);
root.Execute();
}