diff --git a/image-gen.go b/image-gen.go index 0bbc73b..45803cd 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 @@ -93,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 @@ -147,67 +146,69 @@ 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 := 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`") + configPathCPtr := flag.String("c", "", + "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 + configPathC := *configPathCPtr + verbose = *verbosePtr + useConcurreny = *useConcurrenyPtr + + if (configPathC != "") { + configPath = configPathC } - app.Action = func(c *cli.Context) error { - file, _ := os.Open(configPath) - defer file.Close() - decoder := json.NewDecoder(file) - configuration := Config{} + if(configPath=="") { + fmt.Printf("config path parameter required\n") + } - // Set the runtime concurrency level - runtime.GOMAXPROCS(concurrencyLevel) + file, _ := os.Open(configPath) + defer file.Close() + decoder := json.NewDecoder(file) + configuration := Config{} - err := decoder.Decode(&configuration) - if err != nil { - log.Println(err) - } + // Set the runtime concurrency level + runtime.GOMAXPROCS(concurrencyLevel) - 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)) - } + 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) }