implemented general help
This commit is contained in:
		| @@ -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] | ||||
|   | ||||
| @@ -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() | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user