This repository was archived by the owner on Oct 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathmain.go
More file actions
77 lines (67 loc) · 1.72 KB
/
main.go
File metadata and controls
77 lines (67 loc) · 1.72 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"context"
"log"
"os"
"github.com/nhost/hasura-auth/go/cmd"
docs "github.com/urfave/cli-docs/v3"
"github.com/urfave/cli/v3"
)
const (
flagOutput = "output"
)
var Version string
func markdownDocs() *cli.Command {
return &cli.Command{ //nolint:exhaustruct
Name: "docs",
Usage: "Generate markdown documentation for the CLI",
Flags: []cli.Flag{
&cli.StringFlag{ //nolint:exhaustruct
Name: flagOutput,
Usage: "Output file (default: stdout)",
Value: "",
},
},
Action: func(_ context.Context, cmd *cli.Command) error {
md, err := docs.ToMarkdown(cmd.Root())
if err != nil {
return cli.Exit("failed to generate markdown documentation: "+err.Error(), 1)
}
out := os.Stdout
if output := cmd.String(flagOutput); output != "" {
out, err = os.OpenFile(
output,
os.O_CREATE|os.O_WRONLY|os.O_TRUNC,
0o644, //nolint:mnd
)
if err != nil {
return cli.Exit("failed to open output file: "+err.Error(), 1)
}
}
defer out.Close()
if _, err := out.WriteString(md); err != nil {
return cli.Exit("failed to write markdown documentation: "+err.Error(), 1)
}
return nil
},
}
}
//go:generate oapi-codegen -config go/api/server.cfg.yaml docs/openapi.yaml
//go:generate oapi-codegen -config go/api/types.cfg.yaml docs/openapi.yaml
//go:generate go run main.go docs --output docs/cli.md
func main() {
serveCmd := cmd.CommandServe()
app := &cli.Command{ //nolint:exhaustruct
Name: "auth",
Version: Version,
Usage: "Nhost Auth API server",
Flags: serveCmd.Flags,
Commands: []*cli.Command{
markdownDocs(),
},
Action: serveCmd.Action,
}
if err := app.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
}