2025-07-20 00:47:03 +02:00

48 lines
1.0 KiB
Go

package subcommands
import (
"context"
"errors"
"github.com/urfave/cli/v3"
"log/slog"
)
var templateVar bool
// Template Command
func Template() *cli.Command {
return &cli.Command{
Name: "basic",
Usage: "template command usage",
Action: templateAction,
Flags: templateFlags(),
ArgsUsage: "args usage",
}
}
// templateFlags Register cli flags
func templateFlags() []cli.Flag {
return []cli.Flag{
&cli.BoolFlag{
Name: "template",
Aliases: []string{"t"},
Usage: "usage",
Value: false,
DefaultText: "errors template",
Required: false,
Destination: &templateVar,
},
}
}
// templateAction logic for Template
func templateAction(context context.Context, c *cli.Command) error {
slog.InfoContext(context, "template called", "logLevel", "INFO")
slog.DebugContext(context, "template called", "logLevel", "DEBUG")
if templateVar {
slog.ErrorContext(context, "template called", "logLevel", "ERROR")
return errors.New("template called with error")
}
return nil
}