Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Move source to first argument. Add basic help documentation. (#2)
Browse files Browse the repository at this point in the history
* Move src to os.Args. Add help.

* Bin not src.

* Update readme.
  • Loading branch information
ziadoz authored Sep 29, 2019
1 parent 742dc5b commit c13feb3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
26 changes: 20 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,33 @@ 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=<path>] <path>
media-swapper --help
media-swapper --version`

type result struct {
cmd *swap.Cmd
err error
}

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)
Expand All @@ -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)
Expand Down

0 comments on commit c13feb3

Please sign in to comment.