src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

help.go (1019B)


      1 package command
      2 
      3 import (
      4 	"fmt"
      5 	"strings"
      6 	"time"
      7 
      8 	"code.dwrz.net/src/pkg/dqs/command/help"
      9 	"code.dwrz.net/src/pkg/dqs/store"
     10 )
     11 
     12 const (
     13 	helpIntro = `dqs — diet quality score
     14 
     15 Usage:
     16 	dqs [flags] <command> [arguments]
     17 
     18 
     19 Run dqs -help or dqs -h to see information on available flags.
     20 
     21 The following commands are available:
     22 
     23 `
     24 	helpMore = "Run dqs help <command> to see the command's documentation."
     25 )
     26 
     27 var Help = &command{
     28 	execute: showHelp,
     29 
     30 	description: "show built-in command documentation",
     31 	help:        help.Help,
     32 	name:        "help",
     33 }
     34 
     35 func showHelp(args []string, date time.Time, store *store.Store) error {
     36 	if len(args) == 0 {
     37 		var str strings.Builder
     38 
     39 		str.WriteString(helpIntro)
     40 
     41 		for _, c := range commands {
     42 			str.WriteString(
     43 				fmt.Sprintf("%-11s%s\n", c.name, c.description),
     44 			)
     45 		}
     46 
     47 		str.WriteString("\n")
     48 		str.WriteString(helpMore)
     49 
     50 		fmt.Println(str.String())
     51 
     52 		return nil
     53 	}
     54 
     55 	cmd, err := Match(args[0])
     56 	if err != nil {
     57 		return err
     58 	}
     59 
     60 	fmt.Println(cmd.help())
     61 
     62 	return nil
     63 }