This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
101 lines (86 loc) · 2.41 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
package main
import (
"flag"
"fmt"
"os"
"text/tabwriter"
"time"
"github.com/go-kit/kit/log"
"golang.org/x/net/context"
"google.golang.org/grpc"
"strings"
grpcclient "github.com/artefactual-labs/archivematica-workflow/pkg/client/grpc"
"github.com/artefactual-labs/archivematica-workflow/pkg/service/pb"
"github.com/artefactual-labs/archivematica-workflow/pkg/version"
)
func main() {
var (
grpcAddr = flag.String("grpc.addr", ":50050", "gRPC (HTTP) address of archivematica-workflow")
method = flag.String("method", "", "WorkflowGet, ...")
printVersion = flag.Bool("version", false, "Print version")
)
flag.Parse()
if *printVersion {
if version.VERSION == "" {
fmt.Fprintln(os.Stdout, "archivematica-workflow-cli (unknown version)")
} else {
fmt.Fprintf(os.Stdout, "archivematica-workflow-cli %s\n", version.VERSION)
}
os.Exit(1)
}
if *method == "" {
fmt.Fprintf(os.Stderr, "You need to use one of the methods available, e.g. WorkflowGet, ...\n")
fmt.Fprintf(os.Stderr, "For example: archivemica-workflow-cli -method=WorkflowGet default\n")
os.Exit(1)
}
conn, err := grpc.Dial(*grpcAddr, grpc.WithInsecure(), grpc.WithTimeout(time.Second))
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v", err)
os.Exit(1)
}
defer conn.Close()
svc := grpcclient.New(conn, log.NewNopLogger())
switch *method {
case "WorkflowGet":
id := flag.Args()[0]
wf, err := svc.WorkflowGet(context.Background(), id)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
printWorkflow(wf)
default:
fmt.Fprintf(os.Stderr, "error: invalid method %q\n", *method)
os.Exit(1)
}
}
func printWorkflow(wfd *pb.WorkflowData) {
const padding = 3
w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, ' ', tabwriter.DiscardEmptyColumns)
for _, item := range wfd.WatchedDirectories {
row := []string{
fmt.Sprintf("Watched directory: %s", item.Path),
item.Type.String(),
fmt.Sprintf("goes to Chain %s", item.ChainId),
}
fmt.Fprintln(w, strings.Join(row, "\t"))
}
w.Flush()
for id, item := range wfd.Chains {
row := []string{
fmt.Sprintf("Chain %s", id),
item.Description["en"],
fmt.Sprintf("goes to Link %s", item.LinkId),
}
fmt.Fprintln(w, strings.Join(row, "\t"))
}
w.Flush()
for id, item := range wfd.Links {
row := []string{
fmt.Sprintf("Link %s", id),
item.Description["en"],
}
fmt.Fprintln(w, strings.Join(row, "\t"))
}
w.Flush()
}