implemented general help

This commit is contained in:
Hazel Noack 2025-07-16 11:20:58 +02:00
parent 26f1008dc4
commit 81b960c231
2 changed files with 32 additions and 17 deletions

View File

@ -8,35 +8,37 @@ import (
type ProgramFunction func() error type ProgramFunction func() error
type Program struct { type Program struct {
Name string Name string
Function ProgramFunction Function ProgramFunction
Description string ShortDescription string
} }
var HelpHeader = `Meow var HelpHeader = `This is the help page of transfem-startpage.
Ze transfem-startpage {program} {...args}
Dong` The following Programs are available:`
var Programs = []Program{ var Programs = []Program{
{ {
Name: "help", Name: "help",
Function: Help, ShortDescription: "get more information on how the cli in general or a specific program works",
Description: "get more information on how the cli or a program works",
}, },
{ {
Name: "start", Name: "start",
Function: Start, Function: Start,
Description: "start the webserver", ShortDescription: "start the webserver",
}, },
{ {
Name: "cache", Name: "cache",
Function: Cache, Function: Cache,
Description: "do something with the cache", ShortDescription: "do something with the cache",
}, },
} }
func Cli() { func Cli() {
fmt.Println("running transfem startpage") fmt.Println("running transfem startpage")
// getting around initialization cycle
Programs[0].Function = Help
programName := "help" programName := "help"
if len(os.Args) > 1 { if len(os.Args) > 1 {
programName = os.Args[1] programName = os.Args[1]

View File

@ -1,8 +1,21 @@
package cli package cli
import "log" import (
"fmt"
"log"
)
func generalHelp() error {
fmt.Println()
fmt.Println(HelpHeader)
for _, p := range Programs {
fmt.Println(" - " + p.Name + ":\t" + p.ShortDescription)
}
return nil
}
func Help() error { func Help() error {
log.Println("running help") log.Println("running help")
return nil
return generalHelp()
} }