parse CLI args
This commit is contained in:
parent
804bc1c12a
commit
ff145582b0
|
@ -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
23
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 <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)
|
||||
}
|
||||
|
|
9
scan.go
9
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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
Loading…
Reference in New Issue