-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
main.go
49 lines (40 loc) · 1.31 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
package main
import (
"fmt"
"log"
"os"
"github.com/thomaspoignant/go-feature-flag/cmd/migrationcli/converter"
"github.com/jessevdk/go-flags"
)
func main() {
var opts struct {
InputFile string `short:"f" long:"input-file" description:"Location of the flag file you want to convert." required:"true"` //nolint: lll
InputFormat string `long:"input-format" description:"Format of your input file (YAML, JSON or TOML)" required:"true"` //nolint: lll
OutputFile string `short:"o" long:"output-file" description:"Location of the converted flag file." required:"false"` //nolint: lll
OutputFormat string `long:"output-format" description:"Format of your output file (YAML, JSON or TOML)" required:"false"` //nolint: lll
}
_, err := flags.Parse(&opts)
if err != nil {
log.Fatal("impossible to parse command line parameters", err)
}
c := converter.FlagConverter{
InputFile: opts.InputFile,
InputFormat: opts.InputFormat,
OutputFormat: opts.OutputFormat,
}
content, err := c.Migrate()
if err != nil {
log.Fatal(err)
}
err = outputResult(content, opts.OutputFile)
if err != nil {
log.Fatal(err)
}
}
func outputResult(content []byte, outputFile string) error {
if outputFile == "" {
fmt.Println(string(content))
return nil
}
return os.WriteFile(outputFile, content, os.ModePerm)
}