add description to cli help

This commit is contained in:
Lilian Jónsdóttir 2024-07-30 13:18:15 -07:00
parent 11b22887f4
commit c33afe615c

26
main.go
View file

@ -22,8 +22,14 @@ import (
const ( const (
appname string = "gt" appname string = "gt"
appdesc string = "xdg trash cli" appsubtitle string = "xdg trash cli"
appversion string = "v0.0.1" appversion string = "v0.0.1"
appdesc string = `A small command line program to interface with the
Freedesktop.org / XDG trash specification.
Run with no command or filename(s) to start interactive mode.
See gt(1) for more information.`
executePerm = fs.FileMode(0755) executePerm = fs.FileMode(0755)
) )
@ -198,7 +204,7 @@ var (
Name: "trash", Name: "trash",
Aliases: []string{"tr"}, Aliases: []string{"tr"},
Usage: "Trash a file or files", Usage: "Trash a file or files",
Flags: slices.Concat(trashFlags, filterFlags), Flags: slices.Concat(trashingFlags, filterFlags),
Before: beforeTrash, Before: beforeTrash,
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
var filesToTrash files.Files var filesToTrash files.Files
@ -242,7 +248,7 @@ var (
Name: "list", Name: "list",
Aliases: []string{"ls"}, Aliases: []string{"ls"},
Usage: "List trashed files", Usage: "List trashed files",
Flags: slices.Concat(listFlags, alreadyintrashFlags, filterFlags), Flags: slices.Concat(listFlags, trashedFlags, filterFlags),
Before: beforeCommands, Before: beforeCommands,
Action: func(_ *cli.Context) error { Action: func(_ *cli.Context) error {
log.Debugf("searching in directory %s for files", trashDir) log.Debugf("searching in directory %s for files", trashDir)
@ -276,7 +282,7 @@ var (
Name: "restore", Name: "restore",
Aliases: []string{"re"}, Aliases: []string{"re"},
Usage: "Restore a trashed file or files", Usage: "Restore a trashed file or files",
Flags: slices.Concat(cleanRestoreFlags, alreadyintrashFlags, filterFlags), Flags: slices.Concat(cleanRestoreFlags, trashedFlags, filterFlags),
Before: beforeCommands, Before: beforeCommands,
Action: func(_ *cli.Context) error { Action: func(_ *cli.Context) error {
log.Debugf("searching in directory %s for files", trashDir) log.Debugf("searching in directory %s for files", trashDir)
@ -307,7 +313,7 @@ var (
Name: "clean", Name: "clean",
Aliases: []string{"cl"}, Aliases: []string{"cl"},
Usage: "Clean files from trash", Usage: "Clean files from trash",
Flags: slices.Concat(cleanRestoreFlags, alreadyintrashFlags, filterFlags), Flags: slices.Concat(cleanRestoreFlags, trashedFlags, filterFlags),
Before: beforeCommands, Before: beforeCommands,
Action: func(_ *cli.Context) error { Action: func(_ *cli.Context) error {
fls, err := files.FindTrash(trashDir, ogdir, fltr) fls, err := files.FindTrash(trashDir, ogdir, fltr)
@ -334,7 +340,7 @@ var (
globalFlags = []cli.Flag{ globalFlags = []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "log", Name: "log",
Usage: "log level", Usage: "set log level",
Value: "warn", Value: "warn",
Aliases: []string{"l"}, Aliases: []string{"l"},
Destination: &loglvl, Destination: &loglvl,
@ -426,7 +432,7 @@ var (
}, },
} }
trashFlags = []cli.Flag{ trashingFlags = []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "recursive", Name: "recursive",
Usage: "operate on files recursively", Usage: "operate on files recursively",
@ -450,7 +456,7 @@ var (
}, },
} }
alreadyintrashFlags = []cli.Flag{ trashedFlags = []cli.Flag{
&cli.PathFlag{ &cli.PathFlag{
Name: "original-path", Name: "original-path",
Usage: "operate on files trashed from this `DIRECTORY`", Usage: "operate on files trashed from this `DIRECTORY`",
@ -483,13 +489,15 @@ var (
func main() { func main() {
app := &cli.App{ app := &cli.App{
Name: appname, Name: appname,
Usage: appdesc, Usage: appsubtitle,
Version: appversion, Version: appversion,
Before: beforeAll, Before: beforeAll,
After: after, After: after,
Action: action, Action: action,
Commands: []*cli.Command{doTrash, doList, doRestore, doClean}, Commands: []*cli.Command{doTrash, doList, doRestore, doClean},
Flags: globalFlags, Flags: globalFlags,
UsageText: appname + " [global options] [command [command options] / filename(s)]",
Description: appdesc,
EnableBashCompletion: true, EnableBashCompletion: true,
UseShortOptionHandling: true, UseShortOptionHandling: true,
} }