dedupe/settings/arguments.go

51 lines
1.2 KiB
Go

package settings
import (
"os"
"strings"
"velvettear/dedupe/log"
)
// exported function(s)
func Initialize() {
if len(os.Args) < 3 {
log.Fatal("error: missing arguments")
}
for index, arg := range os.Args {
arg = strings.ToLower(arg)
switch arg {
case "-m":
fallthrough
case "--move":
moveDirectoryIndex := index + 1
if moveDirectoryIndex >= len(os.Args) {
log.Fatal("no move directory given")
}
setMoveDirectory(os.Args[index+1])
case "-d":
fallthrough
case "--delete":
setDelete(true)
case "-v":
fallthrough
case "--verbose":
setVerbose(true)
}
}
setSourceDirectory(os.Args[1])
setComparisonDirectory(os.Args[2])
stats, error := os.Stat(SourceDirectory)
if os.IsNotExist(error) {
log.Fatal("given source directory does not exist", SourceDirectory)
}
if !stats.IsDir() {
log.Fatal("given source directory is not a directory", SourceDirectory)
}
stats, error = os.Stat(ComparisonDirectory)
if os.IsNotExist(error) {
log.Fatal("given comparison directory does not exist", ComparisonDirectory)
}
if !stats.IsDir() {
log.Fatal("given comparison directory is not a directory", ComparisonDirectory)
}
}