-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.go
52 lines (42 loc) · 1.15 KB
/
process.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
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"os"
"github.com/konkers/lacodex/ingest"
"github.com/google/subcommands"
)
type processCmd struct{}
func (*processCmd) Name() string { return "process" }
func (*processCmd) Synopsis() string { return "Process and image and output it's JSON record." }
func (*processCmd) Usage() string {
return `process <imange>:
Process and image and output it's JSON record."
`
}
func (p *processCmd) SetFlags(f *flag.FlagSet) {}
func (p *processCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
if len(f.Args()) != 1 {
fmt.Printf("Only one file at a time is supported.\n")
return subcommands.ExitFailure
}
img, err := openImage(f.Args()[0])
if err != nil {
fmt.Printf("%v\n", err)
return subcommands.ExitFailure
}
record, err := ingest.IngestImage(img)
if err != nil {
fmt.Printf("Ingest error: %v\n", err)
return subcommands.ExitFailure
}
b, err := json.MarshalIndent(record, "", " ")
if err != nil {
fmt.Printf("Failed to encode record: %v\n", err)
return subcommands.ExitFailure
}
os.Stdout.Write(b)
return subcommands.ExitSuccess
}