parse CLI args

This commit is contained in:
Stefan Majewsky 2022-04-21 21:27:41 +02:00
parent 804bc1c12a
commit ff145582b0
4 changed files with 47 additions and 7 deletions

11
generate.go Normal file
View File

@ -0,0 +1,11 @@
/*******************************************************************************
* Copyright 2022 Stefan Majewsky <majewsky@gmx.net>
* SPDX-License-Identifier: GPL-3.0-only
* Refer to the file "LICENSE" for details.
*******************************************************************************/
package main
func Generate(scan ScanResult) {
fail("unimplemented")
}

23
main.go
View File

@ -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 <sftp://ftp.c3d2.de>.\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)
}

View File

@ -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
}

11
upload.go Normal file
View File

@ -0,0 +1,11 @@
/*******************************************************************************
* Copyright 2022 Stefan Majewsky <majewsky@gmx.net>
* SPDX-License-Identifier: GPL-3.0-only
* Refer to the file "LICENSE" for details.
*******************************************************************************/
package main
func Upload(scan ScanResult) {
fail("unimplemented")
}