enbas/internal/usage/app.go
Dan Anglin 84091f398d
feat: add Enbas CLI schema and code generator
Summary:

- Created a custom CLI schema for Enbas which will act as the Source
  of Truth for code and document generation.
- Created a code generator which uses the schema to generate the
  executor definitions and code in the internal usage package.

Changes:

- Created the Enbas CLI schema as the Source of Truth for Enbas.
- Created the code generator that generates the executor
  definitions and code in the usage package.
- Regenerated the executor definitions using the code generator.
- Moved the custom flag value types to the new internal flag
  package.
- Created a new flag value type for the bool pointer to replace the
  flag.BoolFunc() used for the sensitive and no-color flags.
- Moved the version and build variables to the new internal version
  package to simplify the version executor.
- Created a new usage package and moved the usage functions there.
- Changed the type of the account-name flag from string to the
  internal StringSliceValue type.
2024-08-13 14:53:26 +01:00

53 lines
1.2 KiB
Go

package usage
import (
"flag"
"fmt"
"slices"
"strings"
"text/tabwriter"
"codeflow.dananglin.me.uk/apollo/enbas/internal/version"
)
func AppUsageFunc() func() {
cmds := make([]string, len(summaries))
ind := 0
for k := range summaries {
cmds[ind] = k
ind++
}
slices.Sort(cmds)
return func() {
var builder strings.Builder
builder.WriteString("SUMMARY:\n enbas - A GoToSocial client for the terminal.\n\n")
if version.BinaryVersion != "" {
builder.WriteString("VERSION:\n " + version.BinaryVersion + "\n\n")
}
builder.WriteString("USAGE:\n enbas [flags]\n enbas [flags] [command]\n\nCOMMANDS:")
tableWriter := tabwriter.NewWriter(&builder, 0, 8, 0, '\t', 0)
for _, cmd := range cmds {
fmt.Fprintf(tableWriter, "\n %s\t%s", cmd, summaries[cmd])
}
tableWriter.Flush()
builder.WriteString("\n\nFLAGS:\n --help\n print the help message")
flag.VisitAll(func(f *flag.Flag) {
fmt.Fprintf(&builder, "\n --%s\n %s", f.Name, f.Usage)
})
builder.WriteString("\n\nUse \"enbas [command] --help\" for more information about a command.\n")
w := flag.CommandLine.Output()
fmt.Fprint(w, builder.String())
}
}