Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made the coma #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 57 additions & 56 deletions image-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"flag"
"log"
"os"
"path/filepath"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}