From 4860e9d9a7d9b865e5e01d32bc1b7fac9bafe2a3 Mon Sep 17 00:00:00 2001 From: NailLegProcessorDivide <53022692+NailLegProcessorDivide@users.noreply.github.com> Date: Thu, 1 Oct 2020 09:59:56 +0100 Subject: [PATCH 1/2] Update image-gen.go --- image-gen.go | 106 +++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/image-gen.go b/image-gen.go index 0bbc73b..98de6cc 100644 --- a/image-gen.go +++ b/image-gen.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "flag" "log" "os" "path/filepath" @@ -11,7 +12,7 @@ import ( "github.com/disintegration/imaging" "github.com/stretchr/powerwalk" - "github.com/urfave/cli" + //"github.com/urfave/cli" ) // PathDirective contains instruction for traversing a path of images @@ -147,67 +148,62 @@ var verbose = false var useConcurreny = true func main() { - concurrencyLevel := 1 - - configPath := "" - app := cli.NewApp() - app.Name = "image-gen" - app.Usage = "build multiple resolution images for a static website" - app.Version = "0.1.0" - app.Author = "Simon Cooksey" - app.EnableBashCompletion = true - - app.Flags = []cli.Flag{ - cli.StringFlag{ - Name: "config, c", - Usage: "Load configuration from `FILE`", - Destination: &configPath, - }, - cli.IntFlag{ - Name: "concurrency-level", - Usage: "Set the number of threads for image-gen to use", - Value: runtime.NumCPU() * 2, - Destination: &concurrencyLevel, - }, - cli.BoolTFlag{ - Name: "no-concurrency", - Usage: "Disable concurrent workers", - Destination: &useConcurreny, - }, - cli.BoolFlag{ - Name: "verbose", - Usage: "Run verbosely", - Destination: &verbose, - }, - } - app.Action = func(c *cli.Context) error { - file, _ := os.Open(configPath) - defer file.Close() - decoder := json.NewDecoder(file) - configuration := Config{} - // Set the runtime concurrency level - runtime.GOMAXPROCS(concurrencyLevel) + //app := cli.NewApp() + //app.Name = "image-gen" + //app.Usage = "build multiple resolution images for a static website" + //app.Version = "0.1.1" + //app.Author = [1]string{"Simon Cooksey"} + //app.EnableBashCompletion = true + flag.String("What", "0.1.1", "0.1.1") + flag.String("Version", "image-gen", "image-gen") + flag.String("Purpose", "build multiple resolution images for a static website", "build multiple resolution images for a static website") + concurrencyLevelPtr := flag.Int("concurrency-level", 1, + "Set the number of threads for image-gen to use") + configPathPtr := flag.String("config", "", + "Load configuration from `FILE`") + verbosePtr := flag.Bool("verbose", false, + "Run verbosely") + useConcurrenyPtr := flag.Bool("no-concurrency", false, + "Disable concurrent workers")//might be bad + flag.Parse() + + concurrencyLevel := *concurrencyLevelPtr + configPath := *configPathPtr + verbose = *verbosePtr + useConcurreny = *useConcurrenyPtr + + if(configPath=="") { + fmt.Printf("config path parameter required\n") + } - err := decoder.Decode(&configuration) - if err != nil { - log.Println(err) - } + file, _ := os.Open(configPath) + defer file.Close() + decoder := json.NewDecoder(file) + configuration := Config{} - for _, path := range configuration.Paths { - path.Path, _ = filepath.Abs(filepath.Clean(path.Path)) - path.Destination, _ = filepath.Abs(filepath.Clean(path.Destination)) - if path.Ignore != "" { - path.Ignore, _ = filepath.Abs(filepath.Clean(path.Ignore)) - } + // Set the runtime concurrency level + runtime.GOMAXPROCS(concurrencyLevel) + + err := decoder.Decode(&configuration) + if err != nil { + log.Println(err) + } - fmt.Printf("%s --> %s\nIgnoring %s\n\n", path.Path, path.Destination, path.Ignore) - resizeDir(path) + for _, path := range configuration.Paths { + path.Path, _ = filepath.Abs(filepath.Clean(path.Path)) + path.Destination, _ = filepath.Abs(filepath.Clean(path.Destination)) + if path.Ignore != "" { + path.Ignore, _ = filepath.Abs(filepath.Clean(path.Ignore)) } - return nil + fmt.Printf("%s --> %s\nIgnoring %s\n\n", path.Path, path.Destination, path.Ignore) + resizeDir(path) } - app.Run(os.Args) + //return nil + //} + + //app.Run(os.Args) } From 9e0d15887c925af37fc24c8941f763258f419a6f Mon Sep 17 00:00:00 2001 From: NailLegProcessorDivide <53022692+NailLegProcessorDivide@users.noreply.github.com> Date: Thu, 1 Oct 2020 15:13:55 +0100 Subject: [PATCH 2/2] Update image-gen.go passed "works on my machine" readiy for actual test --- image-gen.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/image-gen.go b/image-gen.go index 98de6cc..45803cd 100644 --- a/image-gen.go +++ b/image-gen.go @@ -94,10 +94,8 @@ func resizeDir(p PathDirective) { log.Printf("skip this directory: %s\n", path) return nil } - if fileInfo != nil && fileInfo.Mode().IsRegular() { destPath, name, extension := disassemblePaths(p, path) - // ignore dot files if name == "" { return nil @@ -163,6 +161,8 @@ func main() { "Set the number of threads for image-gen to use") configPathPtr := flag.String("config", "", "Load configuration from `FILE`") + configPathCPtr := flag.String("c", "", + "Load configuration from `FILE`") verbosePtr := flag.Bool("verbose", false, "Run verbosely") useConcurrenyPtr := flag.Bool("no-concurrency", false, @@ -171,9 +171,14 @@ func main() { concurrencyLevel := *concurrencyLevelPtr configPath := *configPathPtr + configPathC := *configPathCPtr verbose = *verbosePtr useConcurreny = *useConcurrenyPtr + if (configPathC != "") { + configPath = configPathC + } + if(configPath=="") { fmt.Printf("config path parameter required\n") }