pentaradio-tools/main.go

75 lines
1.6 KiB
Go
Raw Permalink Normal View History

2022-04-17 00:27:08 +02:00
/*******************************************************************************
* Copyright 2022 Stefan Majewsky <majewsky@gmx.net>
* SPDX-License-Identifier: GPL-3.0-only
* Refer to the file "LICENSE" for details.
*******************************************************************************/
package main
2022-04-17 01:57:02 +02:00
import (
"fmt"
"os"
2022-04-21 21:27:41 +02:00
"path/filepath"
2023-11-10 00:09:06 +01:00
"strconv"
2022-04-17 01:57:02 +02:00
)
2022-04-17 00:27:08 +02:00
func main() {
2023-11-10 00:09:06 +01:00
if len(os.Args) < 2 {
2022-04-21 21:27:41 +02:00
usage(1)
}
2023-11-10 00:09:06 +01:00
subcommand, args := os.Args[1], os.Args[2:]
switch subcommand {
2022-04-21 21:27:41 +02:00
case "upload":
2023-11-10 00:09:06 +01:00
if len(args) != 0 {
usage(1)
}
2022-04-21 21:27:41 +02:00
Upload(Scan())
case "generate":
2023-11-10 00:09:06 +01:00
if len(args) != 0 {
usage(1)
}
2022-04-21 21:27:41 +02:00
Generate(Scan())
2023-11-10 00:09:06 +01:00
case "schedule":
if len(args) != 1 {
usage(1)
}
count, err := strconv.ParseUint(args[0], 10, 32)
must(err)
PrintSchedule(count)
2022-04-21 21:27:41 +02:00
case "help", "--help":
2023-11-10 00:09:06 +01:00
if len(args) != 0 {
usage(1)
}
2022-04-21 21:27:41 +02:00
usage(0)
2023-11-10 00:09:06 +01:00
default:
usage(1)
2022-04-21 21:27:41 +02:00
}
2022-04-17 01:57:02 +02:00
}
func must(err error) {
if err != nil {
fail(err.Error())
}
}
func fail(msg string, args ...interface{}) {
if len(args) > 0 {
msg = fmt.Sprintf(msg, args...)
}
2022-04-21 22:55:16 +02:00
fmt.Fprintln(os.Stderr, "ERROR: "+msg)
2022-04-17 01:57:02 +02:00
os.Exit(1)
2022-04-17 00:27:08 +02:00
}
2022-04-21 21:27:41 +02:00
func usage(exitCode int) {
fmt.Fprintf(os.Stderr,
"Usage:\n\n"+
2023-11-10 00:09:06 +01:00
" %[1]s upload - Upload all relevant files for one episode to <sftp://ftp.c3d2.de>.\n"+
" %[1]s generate - Generate the c3d2-web news entry XML file for one episode.\n"+
" %[1]s schedule <N> - Print the next N airdates.\n\n"+
"For `upload` and `generate`, all relevant files (audios, chapter marks file, shownotes Markdown file) must be in the working directory.\n",
2022-04-21 21:27:41 +02:00
filepath.Base(os.Args[0]),
)
os.Exit(exitCode)
}