finished general help

This commit is contained in:
Hazel Noack 2025-07-16 11:45:28 +02:00
parent 7f43eb43e0
commit 51b788bb50
4 changed files with 36 additions and 2 deletions

1
go.mod
View File

@ -5,6 +5,7 @@ go 1.24.2
require github.com/labstack/echo/v4 v4.13.4 require github.com/labstack/echo/v4 v4.13.4
require ( require (
github.com/TwiN/go-color v1.4.1 // indirect
github.com/labstack/gommon v0.4.2 // indirect github.com/labstack/gommon v0.4.2 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect

2
go.sum
View File

@ -1,5 +1,7 @@
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/TwiN/go-color v1.4.1 h1:mqG0P/KBgHKVqmtL5ye7K0/Gr4l6hTksPgTgMk3mUzc=
github.com/TwiN/go-color v1.4.1/go.mod h1:WcPf/jtiW95WBIsEeY1Lc/b8aaWoiqQpu5cf8WFxu+s=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f h1:dKccXx7xA56UNqOcFIbuqFjAWPVtP688j5QMgmo6OHU= github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f h1:dKccXx7xA56UNqOcFIbuqFjAWPVtP688j5QMgmo6OHU=

View File

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"github.com/TwiN/go-color"
) )
type ProgramFunction func() error type ProgramFunction func() error
@ -21,7 +23,7 @@ type Argument struct {
} }
var HelpHeader = `This is the help page of transfem-startpage. var HelpHeader = `This is the help page of transfem-startpage.
transfem-startpage {program} {...args} ` + color.Bold + `transfem-startpage {program} {...args}` + color.Reset + `
The following Programs are available:` The following Programs are available:`
var Programs = []Program{ var Programs = []Program{
{ {

View File

@ -3,13 +3,42 @@ package cli
import ( import (
"fmt" "fmt"
"log" "log"
"github.com/TwiN/go-color"
) )
func padString(s string, n int) string {
missing := n - len(s)
if missing <= 0 {
return s
}
for _ = range missing {
s = s + " "
}
return s
}
func generalHelp() error { func generalHelp() error {
fmt.Println() fmt.Println()
fmt.Println(HelpHeader) fmt.Println(HelpHeader)
fmt.Println()
for _, p := range Programs { for _, p := range Programs {
fmt.Println(" - " + p.Name + ":\t" + p.ShortDescription) fmt.Print(color.Bold + padString(p.Name, 7) + color.Reset)
argumentString := color.Purple
for _, a := range p.Arguments {
requiredString := ""
if a.Required {
requiredString = "*"
}
argumentString = argumentString + " [" + requiredString + a.Name + ":" + a.Type + "]"
}
argumentString = argumentString + color.Reset
fmt.Print(padString(argumentString, 40) + p.ShortDescription + "\n")
} }
return nil return nil
} }