Skip to content

Commit 4c43663

Browse files
authored
Merge pull request #47 from akrabat/46-filename-only-on-resize
Add quiet flag to resize
2 parents bd47ca1 + 0a95b91 commit 4c43663

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

commands/resize.go

+26-9
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,52 @@ package commands
1414

1515
import (
1616
"fmt"
17-
. "github.com/akrabat/rodeo/internal"
18-
"github.com/spf13/cobra"
1917
"os"
2018
"os/exec"
2119
"path/filepath"
2220
"strings"
21+
22+
. "github.com/akrabat/rodeo/internal"
23+
"github.com/spf13/cobra"
2324
)
2425

2526
func init() {
2627
rootCmd.AddCommand(resizeCmd)
28+
29+
// Register command line options
30+
resizeCmd.Flags().BoolP("quiet", "q", false, "Just print name of resized file on completion")
2731
}
2832

2933
// resizeCmd displays info about the image file
3034
var resizeCmd = &cobra.Command{
3135
Use: "resize <files>...",
3236
Short: "Resize files for use on the web",
33-
Long: "Resize files for use on the web",
37+
Long: "Resize files for use on the web",
3438
Run: func(cmd *cobra.Command, args []string) {
3539

3640
if len(args) == 0 {
3741
fmt.Println("Error: At least one file must be specified.")
3842
os.Exit(2)
3943
}
4044

45+
// Read the value of --quiet (if it is missing, the value is false)
46+
quiet, err := cmd.Flags().GetBool("quiet")
47+
if err != nil {
48+
quiet = false
49+
}
50+
4151
for _, filename := range args {
42-
resize(filename)
52+
resize(filename, quiet)
4353
}
4454
},
4555
}
4656

4757
// Resize image using ImageMagick's convert
4858
//
4959
// Example:
50-
// convert foo.jpg -scale 2000x2000 -interpolate catrom -quality 75 foo-web.jpeg
51-
func resize(filename string) {
60+
//
61+
// convert foo.jpg -scale 2000x2000 -interpolate catrom -quality 75 foo-web.jpeg
62+
func resize(filename string, quiet bool) {
5263

5364
config := GetConfig()
5465
convert := config.Cmd.Convert
@@ -74,12 +85,18 @@ func resize(filename string) {
7485
parameters = append(parameters, quality)
7586
parameters = append(parameters, newFilename)
7687

77-
fmt.Printf("Resizing to %s at %s%% quality\n", scale, quality)
88+
if !quiet {
89+
fmt.Printf("Resizing to %s at %s%% quality\n", scale, quality)
90+
}
7891
cmd := exec.Command(convert, parameters...)
7992
cmd.Dir = filepath.Dir(filename)
8093
if err := cmd.Run(); err != nil {
8194
fmt.Println("Error: ", err)
8295
os.Exit(1)
8396
}
84-
fmt.Printf(" Saved %v\n", newFilename)
85-
}
97+
if quiet {
98+
fmt.Printf("%v\n", newFilename)
99+
} else {
100+
fmt.Printf(" Saved %v\n", newFilename)
101+
}
102+
}

0 commit comments

Comments
 (0)