Browse Source

Added format flag and prettified output

Signed-off-by: gryffyn <me@neveris.one>
feature/autoindex
gryffyn 11 months ago
parent
commit
cad950f6ec
Signed by: gryffyn GPG Key ID: 6948DD6514D02BEF
  1. 6
      go.mod
  2. 45
      main.go

6
go.mod

@ -2,4 +2,8 @@ module git.neveris.one/gryffyn/exren
go 1.15
require github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
require (
github.com/logrusorgru/aurora/v3 v3.0.0
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
github.com/urfave/cli/v2 v2.3.0
)

45
main.go

@ -1,22 +1,49 @@
package main
import (
"fmt"
"log"
"os"
"git.neveris.one/gryffyn/exren/parser"
. "github.com/logrusorgru/aurora/v3"
"github.com/urfave/cli/v2"
)
func main() {
format := `%DateTimeOriginal%-gryffyn.jpg`
path := "test.jpg"
exifData := parser.NewExif(path)
_ = exifData.Parse()
newpath := parser.ParseFormat(format, exifData.Tags)
println("PATH: " + path)
println("NEWPATH: " + newpath)
err := os.Rename(path, newpath)
func Run() {
var format string
app := &cli.App{
Name: "exren",
Version: "0.1.0",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "format",
Aliases: []string{"f"},
Usage: "Output format, including extension",
Destination: &format,
Required: true,
},
},
Action: func(c *cli.Context) error {
err := rename(format, c.Args().Get(0))
return err
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func rename(format, path string) error {
exifData := parser.NewExif(path)
_ = exifData.Parse()
newpath := parser.ParseFormat(format, exifData.Tags)
fmt.Println(Bold(Green("✓")), Bold("Renamed to:"), newpath)
return os.Rename(path, newpath)
}
func main() {
Run()
}

Loading…
Cancel
Save