-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
158 lines (145 loc) · 3.65 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package main
import (
"fmt"
"os"
"github.com/starlinglab/integrity-v2/c2pa"
"github.com/starlinglab/integrity-v2/cid"
"github.com/starlinglab/integrity-v2/decrypt"
"github.com/starlinglab/integrity-v2/encrypt"
"github.com/starlinglab/integrity-v2/export"
"github.com/starlinglab/integrity-v2/genkey"
"github.com/starlinglab/integrity-v2/get"
preprocessorfolder "github.com/starlinglab/integrity-v2/preprocessor/folder"
"github.com/starlinglab/integrity-v2/register"
"github.com/starlinglab/integrity-v2/relate"
"github.com/starlinglab/integrity-v2/search"
"github.com/starlinglab/integrity-v2/set"
"github.com/starlinglab/integrity-v2/sync"
"github.com/starlinglab/integrity-v2/upload"
"github.com/starlinglab/integrity-v2/util"
"github.com/starlinglab/integrity-v2/webhook"
)
// Main file for all-in-one build
var helpText = `This binary contains all the CLI tools and services in one.
Remote/network commands:
starling attr get
starling attr set
starling attr export
starling attr search
starling attr relate
Commands to run on the server:
starling genkey
starling file upload
starling file encrypt
starling file decrypt
starling file register
starling file cid
starling file c2pa
Further documentation on CLI tools is listed online:
https://github.com/starlinglab/integrity-v2/blob/main/docs/cli.md
Other than that, services are included:
preprocessor-folder
webhook
sync
And finally, the version or --version command will display the build version.`
func run(group string, args []string) (bool, error) {
// group is "attr" or "file" or an ungrouped cmd like "sync"
// cmd is the grouped cmd like "upload"
var cmd string
if len(args) > 0 && group == "attr" || group == "file" {
// Not a short form
cmd = args[0]
args = args[1:]
}
var err error
switch group {
// Groups
case "attr":
switch cmd {
case "":
return true, fmt.Errorf("provide a subcommand")
case "get":
err = get.Run(args)
case "set":
err = set.Run(args)
case "search":
err = search.Run(args)
case "export":
err = export.Run(args)
case "relate":
err = relate.Run(args)
default:
// Unknown command
return false, nil
}
case "file":
switch cmd {
case "":
return true, fmt.Errorf("provide a subcommand")
case "upload":
err = upload.Run(args)
case "encrypt":
err = encrypt.Run(args)
case "decrypt":
err = decrypt.Run(args)
case "register":
err = register.Run(args)
case "cid":
err = cid.Run(args)
case "c2pa":
err = c2pa.Run(args)
default:
// Unknown command
return false, nil
}
// Ungrouped commands
case "genkey":
// cmd is just another arg in this case
err = genkey.Run(args)
case "webhook":
err = webhook.Run(args)
case "preprocessor-folder":
err = preprocessorfolder.Run(args)
case "sync":
err = sync.Run(args)
// Helpers / metadata
case "-h", "--help", "help":
fmt.Println(helpText)
case "version", "--version":
fmt.Println(util.Version())
// Short forms
case "g":
err = get.Run(args)
case "s":
err = search.Run(args)
case "c":
err = cid.Run(args)
default:
// Unknown command
return false, nil
}
return true, err
}
func main() {
if len(os.Args) == 1 {
fmt.Println(helpText)
return
}
var ok bool
var err error
if len(os.Args) == 2 {
// Could be invalid "starling file"
// Or valid "starling genkey"
ok, err = run(os.Args[1], []string{})
} else {
// 2+ args after "starling", like "starling file cid"
ok, err = run(os.Args[1], os.Args[2:])
}
if !ok {
// If that fails too then give up
fmt.Fprintln(os.Stderr, "unknown command")
os.Exit(1)
}
// Command was run, either successfully or with error
util.Fatal(err)
}