-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
115 lines (103 loc) · 2.67 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"fmt"
"github.com/jsightapi/cli/internal/argparser"
"github.com/jsightapi/cli/internal/format"
"os"
cli "github.com/urfave/cli/v2"
)
var (
Version = "1.1.0"
)
var statDisclaimer = " By default, the application sends anonymous usage and error statistics to JSight to help improve the product.\n Use the -s option to stop sending the statistics."
func main() {
if err := run(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}
func run() error {
app := &cli.App{
Name: "jsight",
Usage: fmt.Sprintf("is a tool for working with files in the JSight language.\n\n%s", statDisclaimer),
Commands: []*cli.Command{
{
Name: "doc",
Usage: "generate API documentation in various formats",
Subcommands: []*cli.Command{
{
Name: "html",
Usage: "generates documentation in HTML format",
Flags: []cli.Flag{},
ArgsUsage: "<input>",
Action: makeResult(format.FormatHTML),
}, /*
{
Name: "pdf",
Usage: "generates documentation in PDF format",
ArgsUsage: "<input>",
Action: generateDocumentation(generator.FormatPDF),
},
{
Name: "docx",
Usage: "generates documentation in DOCX format",
ArgsUsage: "<input>",
Action: generateDocumentation(generator.FormatDOCX),
},*/
},
},
{
Name: "convert",
Usage: "converts JSight to other formats",
Subcommands: []*cli.Command{
{
Name: "openapi",
Usage: "converts JSight to OpenAPI JSON or YAML",
Subcommands: []*cli.Command{
{
Name: "json",
Usage: "converts JSight to OpenAPI JSON",
Flags: []cli.Flag{},
ArgsUsage: "<input>",
Action: makeResult(format.FormatJSON),
},
{
Name: "yaml",
Usage: "converts JSight to OpenAPI YAML",
Flags: []cli.Flag{},
ArgsUsage: "<input>",
Action: makeResult(format.FormatYAML),
},
},
},
},
},
{
Name: "version",
Usage: "print tool version",
Action: printVersion,
},
},
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "s",
Usage: "disables the sending of anonymous usage and error statistics to JSight",
DefaultText: "enabled",
},
},
}
return app.Run(os.Args)
}
func makeResult(f format.Format) func(ctx *cli.Context) error {
return func(ctx *cli.Context) error {
return argparser.DoWork(ctx, f)
}
}
func printVersion(ctx *cli.Context) error {
_, err := fmt.Fprintf(ctx.App.Writer, `Version: %s
--
%s
`, Version, statDisclaimer)
return err
}