From 81b960c23157882066f93ea3fc96b50e79ba28aa Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Wed, 16 Jul 2025 11:20:58 +0200 Subject: [PATCH] implemented general help --- internal/cli/cli.go | 32 +++++++++++++++++--------------- internal/cli/help.go | 17 +++++++++++++++-- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 965bb39..39611cb 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -8,35 +8,37 @@ import ( type ProgramFunction func() error type Program struct { - Name string - Function ProgramFunction - Description string + Name string + Function ProgramFunction + ShortDescription string } -var HelpHeader = `Meow -Ze -Dong` +var HelpHeader = `This is the help page of transfem-startpage. +transfem-startpage {program} {...args} +The following Programs are available:` var Programs = []Program{ { - Name: "help", - Function: Help, - Description: "get more information on how the cli or a program works", + Name: "help", + ShortDescription: "get more information on how the cli in general or a specific program works", }, { - Name: "start", - Function: Start, - Description: "start the webserver", + Name: "start", + Function: Start, + ShortDescription: "start the webserver", }, { - Name: "cache", - Function: Cache, - Description: "do something with the cache", + Name: "cache", + Function: Cache, + ShortDescription: "do something with the cache", }, } func Cli() { fmt.Println("running transfem startpage") + // getting around initialization cycle + Programs[0].Function = Help + programName := "help" if len(os.Args) > 1 { programName = os.Args[1] diff --git a/internal/cli/help.go b/internal/cli/help.go index 2504940..546c42d 100644 --- a/internal/cli/help.go +++ b/internal/cli/help.go @@ -1,8 +1,21 @@ 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 { log.Println("running help") - return nil + + return generalHelp() }