mirror of
https://lab.forgefriends.org/friendlyforgeformat/gof3.git
synced 2025-10-06 05:42:45 +02:00
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
// Copyright Earl Warren <contact@earl-warren.org>
|
|
// Copyright Loïc Dachary <loic@dachary.org>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
|
|
"lab.forgefriends.org/friendlyforgeformat/gof3/logger"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var Version = "3.0.0"
|
|
|
|
func SetVerbosity(ctx context.Context, verbosity int) {
|
|
l := logger.ContextGetLogger(ctx)
|
|
switch verbosity {
|
|
case 0:
|
|
l.SetLevel(logger.Info)
|
|
default:
|
|
l.SetLevel(logger.Trace)
|
|
}
|
|
}
|
|
|
|
func NewApp(ctx context.Context) *cli.App {
|
|
app := cli.NewApp()
|
|
app.Name = "F3"
|
|
app.Usage = "Friendly Forge Format"
|
|
app.Description = `Friendly Forge Format`
|
|
app.Version = Version
|
|
app.Commands = []*cli.Command{
|
|
CreateCmdMirror(ctx),
|
|
}
|
|
|
|
defaultFlags := []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "verbose",
|
|
Usage: "increase the verbosity level",
|
|
},
|
|
cli.VersionFlag,
|
|
}
|
|
app.Before = func(c *cli.Context) error {
|
|
SetVerbosity(ctx, c.Count("verbose"))
|
|
return nil
|
|
}
|
|
|
|
app.Flags = append(app.Flags, defaultFlags...)
|
|
app.EnableBashCompletion = true
|
|
return app
|
|
}
|