diff --git a/generate.go b/generate.go new file mode 100644 index 0000000..31c9155 --- /dev/null +++ b/generate.go @@ -0,0 +1,11 @@ +/******************************************************************************* +* Copyright 2022 Stefan Majewsky +* SPDX-License-Identifier: GPL-3.0-only +* Refer to the file "LICENSE" for details. +*******************************************************************************/ + +package main + +func Generate(scan ScanResult) { + fail("unimplemented") +} diff --git a/main.go b/main.go index 75c8b40..1ab8c63 100644 --- a/main.go +++ b/main.go @@ -9,9 +9,21 @@ package main import ( "fmt" "os" + "path/filepath" ) func main() { + if len(os.Args) != 2 { + usage(1) + } + switch os.Args[1] { + case "upload": + Upload(Scan()) + case "generate": + Generate(Scan()) + case "help", "--help": + usage(0) + } scanResult := Scan() fmt.Printf("%#v", scanResult) } @@ -29,3 +41,14 @@ func fail(msg string, args ...interface{}) { fmt.Fprintln(os.Stderr, "ERROR: ", msg) os.Exit(1) } + +func usage(exitCode int) { + fmt.Fprintf(os.Stderr, + "Usage:\n\n"+ + " %[1]s upload - Upload all relevant files for one episode to .\n"+ + " %[1]s generate - Generate the c3d2-web news entry XML file for one episode.\n\n"+ + "All relevant files (audios, chapter marks file, shownotes Markdown file) must be in the working directory.\n", + filepath.Base(os.Args[0]), + ) + os.Exit(exitCode) +} diff --git a/scan.go b/scan.go index 40421ce..016f181 100644 --- a/scan.go +++ b/scan.go @@ -21,7 +21,7 @@ type ScanResult struct { Month int Year int //files discovered - AudioFormats []string + AudioFileNames []string //parts extracted from the shownotes Title string Description string @@ -71,16 +71,11 @@ func Scan() (result ScanResult) { //collect audio files pattern := fmt.Sprintf("pentaradio-%04d-%02d-%02d.*", result.Year, result.Month, result.Day) - names, err = filepath.Glob(pattern) + result.AudioFileNames, err = filepath.Glob(pattern) must(err) if len(names) == 0 { fail("no files found: %s", pattern) } - for _, name := range names { - result.AudioFormats = append(result.AudioFormats, strings.TrimPrefix(filepath.Ext(name), ".")) - } - - //TODO: parse chapter marks return } diff --git a/upload.go b/upload.go new file mode 100644 index 0000000..5f1c322 --- /dev/null +++ b/upload.go @@ -0,0 +1,11 @@ +/******************************************************************************* +* Copyright 2022 Stefan Majewsky +* SPDX-License-Identifier: GPL-3.0-only +* Refer to the file "LICENSE" for details. +*******************************************************************************/ + +package main + +func Upload(scan ScanResult) { + fail("unimplemented") +}