add --identify
This commit is contained in:
parent
da03400035
commit
ace99c8aa8
|
@ -0,0 +1,24 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// print the protobuf in human form
|
||||||
|
func doIdentify(filename string) error {
|
||||||
|
data, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
// log.Info("open config file :", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var pb *Identify
|
||||||
|
pb = new(Identify)
|
||||||
|
if err := pb.Unmarshal(data); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Info("Identify protobuf file uuid =", pb.Uuid, "version =", pb.Version)
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -98,5 +98,5 @@ message Files { // `autogenpb:marshal`
|
||||||
// then dump the uuid and version from any arbitrary .pb file
|
// then dump the uuid and version from any arbitrary .pb file
|
||||||
message Identify { // `autogenpb:marshal`
|
message Identify { // `autogenpb:marshal`
|
||||||
string uuid = 1; //
|
string uuid = 1; //
|
||||||
int64 version = 2; //
|
string version = 2; //
|
||||||
}
|
}
|
||||||
|
|
7
main.go
7
main.go
|
@ -34,6 +34,13 @@ func main() {
|
||||||
var pb *Files
|
var pb *Files
|
||||||
pb = new(Files)
|
pb = new(Files)
|
||||||
|
|
||||||
|
if argv.Identify != "" {
|
||||||
|
if err := doIdentify(argv.Identify); err != nil {
|
||||||
|
badExit(err)
|
||||||
|
}
|
||||||
|
okExit("")
|
||||||
|
}
|
||||||
|
|
||||||
// you need a proto file
|
// you need a proto file
|
||||||
if argv.Proto == "" {
|
if argv.Proto == "" {
|
||||||
log.Info("you must provide --proto <filename>")
|
log.Info("you must provide --proto <filename>")
|
||||||
|
|
Loading…
Reference in New Issue