+30
-15
src/main.go
+30
-15
src/main.go
···
81
81
}
82
82
}
83
83
84
+
func fileOutputArg() (writer io.WriteCloser) {
85
+
var err error
86
+
if flag.NArg() == 0 {
87
+
writer = os.Stdout
88
+
} else {
89
+
writer, err = os.Create(flag.Arg(0))
90
+
if err != nil {
91
+
log.Fatalln(err)
92
+
}
93
+
}
94
+
return
95
+
}
96
+
84
97
func Main() {
85
98
printConfigEnvVars := flag.Bool("print-config-env-vars", false,
86
99
"print every recognized configuration environment variable and exit")
···
91
104
noConfig := flag.Bool("no-config", false,
92
105
"run without configuration file (configure via environment variables)")
93
106
runMigration := flag.String("run-migration", "",
94
-
"run a specific store migration (available: \"create-domain-markers\")")
107
+
"run a store `migration` (one of: create-domain-markers)")
95
108
getBlob := flag.String("get-blob", "",
96
-
"write contents of `blob-ref` ('sha256-xxxxxxx...xxx') to stdout")
109
+
"write contents of `blob` ('sha256-xxxxxxx...xxx')")
97
110
getManifest := flag.String("get-manifest", "",
98
-
"write manifest for `site-name` (either 'domain.tld' or 'domain.tld/dir') to stdout as ProtoJSON")
111
+
"write manifest for `site` (either 'domain.tld' or 'domain.tld/dir') as ProtoJSON")
99
112
getArchive := flag.String("get-archive", "",
100
-
"write archive for `site-name` (either 'domain.tld' or 'domain.tld/dir') to stdout in tar format")
113
+
"write archive for `site` (either 'domain.tld' or 'domain.tld/dir') in tar format")
101
114
updateSite := flag.String("update-site", "",
102
-
"update site for `site-name` (either 'domain.tld' or 'domain.tld/dir') from archive or repository URL")
115
+
"update `site` (either 'domain.tld' or 'domain.tld/dir') from archive or repository URL")
103
116
flag.Parse()
104
117
105
118
var cliOperations int
···
183
196
if err != nil {
184
197
log.Fatalln(err)
185
198
}
186
-
187
-
io.Copy(os.Stdout, reader)
199
+
io.Copy(fileOutputArg(), reader)
188
200
189
201
case *getManifest != "":
190
202
if err := ConfigureBackend(&config.Storage); err != nil {
···
196
208
if err != nil {
197
209
log.Fatalln(err)
198
210
}
199
-
fmt.Println(ManifestDebugJSON(manifest))
211
+
fmt.Fprintln(fileOutputArg(), ManifestDebugJSON(manifest))
200
212
201
213
case *getArchive != "":
202
214
if err := ConfigureBackend(&config.Storage); err != nil {
···
209
221
if err != nil {
210
222
log.Fatalln(err)
211
223
}
212
-
CollectTar(context.Background(), os.Stdout, manifest, manifestMtime)
224
+
CollectTar(context.Background(), fileOutputArg(), manifest, manifestMtime)
213
225
214
226
case *updateSite != "":
215
227
if err := ConfigureBackend(&config.Storage); err != nil {
216
228
log.Fatalln(err)
217
229
}
218
230
219
-
sourceURL, _ := url.Parse(flag.Arg(0))
220
-
if sourceURL == nil || *sourceURL == (url.URL{}) {
221
-
log.Fatalln("update source must be provided as an argument")
231
+
if flag.NArg() != 1 {
232
+
log.Fatalln("update source must be provided as the argument")
222
233
}
223
234
224
-
webRoot := *updateSite
225
-
if !strings.Contains(webRoot, "/") {
226
-
webRoot += "/.index"
235
+
sourceURL, err := url.Parse(flag.Arg(0))
236
+
if err != nil {
237
+
log.Fatalln(err)
227
238
}
228
239
229
240
var result UpdateResult
···
232
243
if err != nil {
233
244
log.Fatalln(err)
234
245
}
246
+
defer file.Close()
235
247
236
248
var contentType string
237
249
switch {
···
247
259
log.Fatalf("cannot determine content type from filename %q\n", sourceURL)
248
260
}
249
261
262
+
webRoot := webRootArg(*updateSite)
250
263
result = UpdateFromArchive(context.Background(), webRoot, contentType, file)
251
264
} else {
252
265
branch := "pages"
253
266
if sourceURL.Fragment != "" {
254
267
branch, sourceURL.Fragment = sourceURL.Fragment, ""
255
268
}
269
+
270
+
webRoot := webRootArg(*updateSite)
256
271
result = UpdateFromRepository(context.Background(), webRoot, sourceURL.String(), branch)
257
272
}
258
273