-
Notifications
You must be signed in to change notification settings - Fork 1
/
open2opaque.go
73 lines (56 loc) · 1.93 KB
/
open2opaque.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
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// The program open2opaque migrates Go code using Go Protobuf from the Open API
// to the Opaque API.
//
// See https://go.dev/blog/protobuf-opaque for context.
package main
import (
"context"
"fmt"
"io"
_ "net/http/pprof"
"os"
"path"
"flag"
"github.com/google/subcommands"
"google.golang.org/open2opaque/internal/o2o/rewrite"
"google.golang.org/open2opaque/internal/o2o/setapi"
"google.golang.org/open2opaque/internal/o2o/version"
)
const groupOther = "working with this tool"
func registerVersion(commander *subcommands.Commander) {
commander.Register(version.Command(), groupOther)
}
func main() {
ctx := context.Background()
commander := subcommands.NewCommander(flag.CommandLine, path.Base(os.Args[0]))
// Prepend general documentation before the regular help output.
defaultExplain := commander.Explain
commander.Explain = func(w io.Writer) {
fmt.Fprintf(w, `The open2opaque tool migrates Go packages from the Go Protobuf Open Struct API to the Opaque API.
For documentation, see:
* https://go.dev/blog/protobuf-opaque
* https://protobuf.dev/reference/go/opaque-migration/
Report issues at https://github.com/golang/open2opaque/issues
`)
defaultExplain(w)
}
// Comes last in the help output (alphabetically)
commander.Register(commander.HelpCommand(), groupOther)
commander.Register(commander.FlagsCommand(), groupOther)
registerVersion(commander)
// Comes first in the help output (alphabetically)
const groupRewrite = "automatically rewriting Go code"
commander.Register(rewrite.Command(), groupRewrite)
const groupFlag = "managing the API level"
commander.Register(setapi.Command(), groupFlag)
flag.Usage = func() {
commander.HelpCommand().Execute(ctx, flag.CommandLine)
}
flag.Parse()
code := int(commander.Execute(ctx))
logFlush()
os.Exit(code)
}