1
0

paths safeguard

This commit is contained in:
2022-05-04 10:22:02 +02:00
parent 1d827f6ea1
commit b0ab18b1a8
3 changed files with 30 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"flag"
"fmt"
"log"
"os"
"strconv"
"strings"
@ -48,13 +49,35 @@ func (c *Config) SetOutputDimensions() {
c.OutputHeight = height
}
func (c *Config) CheckPaths() {
_, err := os.Stat(c.OutputDir)
if err != nil {
log.Fatal("Output dir does not exist :", c.OutputDir)
}
_, err = os.Stat(c.InputDir)
if err != nil {
log.Fatal("Input dir does not exist :", c.InputDir)
}
if (c.BaseImage != "") {
_, err = os.Stat(c.BaseImage)
if err != nil {
log.Fatal("Base image does not exist :", c.BaseImage)
}
}
}
func initConfigRegister() {
// default seed for the RNG
seed := time.Now().UnixNano()
// command line arguments
flag.StringVar(&ConfigRegister.Method, "blending", "darken", "Blending methods : darken, lighten, average, fuckyfun")
flag.StringVar(&ConfigRegister.OutputDir, "output", "./", "Output directory")
flag.StringVar(&ConfigRegister.OutputDir, "output", "./output", "Output directory")
flag.StringVar(&ConfigRegister.InputDir, "input", "/home/gator/Photos", "Input directory. Where to look the images from")
flag.StringVar(&ConfigRegister.BaseImage, "base-img", "", "Path to the base image to work with. Random image if not set")
flag.StringVar(&ConfigRegister.Dimensions, "dimensions", "1280x1024", "Out image dimensions. <width>x<height>")
@ -66,6 +89,8 @@ func initConfigRegister() {
flag.Parse()
ConfigRegister.CheckPaths()
// set output's width and height
ConfigRegister.SetOutputDimensions()
}