From c13feb3b1a1958bbcc4248756d977aa97b94eda6 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Sun, 29 Sep 2019 21:43:03 +0100 Subject: [PATCH] Move source to first argument. Add basic help documentation. (#2) * Move src to os.Args. Add help. * Bin not src. * Update readme. --- README.md | 9 +++++++-- cmd/main.go | 26 ++++++++++++++++++++------ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 534ca25..3813751 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,15 @@ You'll need to have either [ffmpeg](https://ffmpeg.org/) or [avconv](https://lib ## Usage You can convert all the media in the current directory by just running the script: ``` -./media-swapper --src=/path/to/videos +media-swapper /path/to/videos ``` You can also specify the binary if required: ``` -./media-swapper --src=/path/to/videos --bin=/path/to/ffmpeg-or-avconv +media-swapper /path/to/videos --bin=/path/to/ffmpeg-or-avconv +``` + +If you need to know the version you are using, there's a flag for that: +``` +media-swapper --version ``` diff --git a/cmd/main.go b/cmd/main.go index 73cd198..941bfd2 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -22,11 +22,17 @@ var ( ) var ( - ver bool - bin pathflag.Path - src pathflag.Path + ver bool + help bool + bin pathflag.Path ) +var usage = `Media Swapper is a simple tool for container swapping m4a audio to mp3, and mkv video to mp4. + +Usage: media-swapper [--bin=] + media-swapper --help + media-swapper --version` + type result struct { cmd *swap.Cmd err error @@ -34,10 +40,15 @@ type result struct { func main() { flag.BoolVar(&ver, "version", false, "The version of media swapper") + flag.BoolVar(&help, "help", false, "Show command usage instructions and help") flag.Var(&bin, "bin", "The location of the ffmpeg or avconv binary") - flag.Var(&src, "src", "The source directory of mkv/m4a files or an individual mkv/m4a file to swap to mp4/mp3") flag.Parse() + if help { + fmt.Println(usage) + os.Exit(0) + } + if ver { fmt.Printf("Version: %s\nCommit: %s\nDate: %s\n", version, commit, date) os.Exit(0) @@ -58,11 +69,14 @@ func main() { os.Exit(1) } - if src.Path == "" { - fmt.Fprintln(os.Stderr, "The -src flag must be specified") + if len(os.Args) == 1 { + fmt.Fprintln(os.Stderr, "A source must be specified") os.Exit(1) } + src := pathflag.Path{} + src.Set(os.Args[1]) + files, err := fs.GetSwappableFiles(src) if err != nil { fmt.Fprintf(os.Stderr, "Could not find mkv/m4a files: %s\n", err)