cli #1

Merged
Hazel merged 13 commits from cli into main 2025-07-16 14:35:52 +00:00
5 changed files with 89 additions and 1 deletions
Showing only changes of commit 26f1008dc4 - Show all commits

8
internal/cli/cache.go Normal file
View File

@ -0,0 +1,8 @@
package cli
import "log"
func Cache() error {
log.Println("running cache")
return nil
}

59
internal/cli/cli.go Normal file
View File

@ -0,0 +1,59 @@
package cli
import (
"fmt"
"log"
"os"
)
type ProgramFunction func() error
type Program struct {
Name string
Function ProgramFunction
Description string
}
var HelpHeader = `Meow
Ze
Dong`
var Programs = []Program{
{
Name: "help",
Function: Help,
Description: "get more information on how the cli or a program works",
},
{
Name: "start",
Function: Start,
Description: "start the webserver",
},
{
Name: "cache",
Function: Cache,
Description: "do something with the cache",
},
}
func Cli() {
fmt.Println("running transfem startpage")
programName := "help"
if len(os.Args) > 1 {
programName = os.Args[1]
}
log.Println("running program", programName)
var selectedProgram *Program = nil
for i, p := range Programs {
if p.Name == programName {
selectedProgram = &Programs[i]
break
}
}
if selectedProgram == nil {
log.Panicln("couldn't find program", programName, ". EXITING")
}
selectedProgram.Function()
}

8
internal/cli/help.go Normal file
View File

@ -0,0 +1,8 @@
package cli
import "log"
func Help() error {
log.Println("running help")
return nil
}

8
internal/cli/start.go Normal file
View File

@ -0,0 +1,8 @@
package cli
import "log"
func Start() error {
log.Println("starting server")
return nil
}

View File

@ -11,6 +11,7 @@ import (
"os"
"strconv"
"gitea.elara.ws/Hazel/transfem-startpage/internal/cli"
"gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt"
"gitea.elara.ws/Hazel/transfem-startpage/internal/rendering"
"github.com/labstack/echo/v4"
@ -60,7 +61,7 @@ func getFileSystem() http.FileSystem {
return http.FS(fsys)
}
func main() {
func backMain() {
profile := "default"
if len(os.Args) > 1 {
profile = os.Args[1]
@ -100,3 +101,7 @@ func main() {
e.Logger.Fatal(e.Start(":" + strconv.Itoa(CurrentConfig.Server.Port)))
}
func main() {
cli.Cli()
}