1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
package cli
import (
"context"
"fmt"
"log"
"strconv"
"strings"
"github.com/la5nta/pat/app"
)
const (
TemplatesUsage = `subcommand [option ...]
subcommands:
update Update standard Winlink form templates.
seqset [number] Set the template sequence value.
`
TemplatesExample = `
update Download the latest form templates from winlink.org.
seqset 0 Reset the current sequence value to 0.
`
)
func shiftArgs(s []string) (string, []string) {
if len(s) == 0 {
return "", nil
}
return strings.TrimSpace(s[0]), s[1:]
}
func TemplatesHandle(ctx context.Context, app *app.App, args []string) {
switch cmd, args := shiftArgs(args); cmd {
case "update":
if _, err := app.FormsManager().UpdateFormTemplates(ctx); err != nil {
log.Printf("%v", err)
}
case "seqset":
v, err := strconv.Atoi(args[0])
if err != nil {
log.Printf("invalid sequence number: %q", args[0])
return
}
if err := app.FormsManager().SeqSet(v); err != nil {
log.Fatal(err)
}
default:
fmt.Println("Missing argument, try 'templates help'.")
}
}
|