-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
65 lines (57 loc) · 1.18 KB
/
main.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"errors"
"log"
"os"
"strings"
"github.com/traefik/seo/sitemap"
"github.com/traefik/seo/transform"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "seo",
Description: "Documentation modification for SEO.",
Usage: "SEO doc",
Flags: []cli.Flag{
&cli.StringFlag{
Name: transform.FlagPath,
Usage: "Path of the documentation.",
},
&cli.StringFlag{
Name: transform.FlagProduct,
Usage: "Product name.",
},
},
Action: func(cliCtx *cli.Context) error {
config := transform.NewConfig(cliCtx)
err := validate(config)
if err != nil {
return err
}
return transform.Run(config)
},
Commands: []*cli.Command{
{
Name: "version",
Usage: "Version information.",
Description: "Version information.",
Action: func(cliCtx *cli.Context) error {
displayVersion()
return nil
},
},
sitemap.Command(),
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal("Error while executing command ", err)
}
}
func validate(cfg transform.Config) error {
if strings.TrimSpace(cfg.Path) == "" {
return errors.New("path is required")
}
return nil
}