From b1bc8cd24bc637dde9c7f5dc082cb8941d24fd4e Mon Sep 17 00:00:00 2001 From: Yieldone Date: Fri, 26 Jul 2024 17:27:58 +0800 Subject: [PATCH 1/2] refactor: rename sub-cmd 'border' to 'style' --- README.md | 22 +++++++++---------- cmd/cmds_style.go | 18 +++++++-------- cmd/{border => style}/logo_melon.go | 9 ++++---- cmd/{border => style}/simple.go | 9 ++++---- cmd/{border => style}/text_bottom.go | 9 ++++---- service/{border => style}/handler.go | 15 ++++++------- .../{border/styles => style}/logo_melon.go | 4 ++-- .../styles => style}/logo_melon_parameter.go | 2 +- service/{border/styles => style}/simple.go | 2 +- .../styles => style}/simple_parameter.go | 2 +- .../{border => style}/styles_common/funcs.go | 0 .../{border/styles => style}/text_bottom.go | 4 ++-- .../styles => style}/text_bottom_parameter.go | 2 +- 13 files changed, 47 insertions(+), 51 deletions(-) rename cmd/{border => style}/logo_melon.go (89%) rename cmd/{border => style}/simple.go (85%) rename cmd/{border => style}/text_bottom.go (88%) rename service/{border => style}/handler.go (85%) rename service/{border/styles => style}/logo_melon.go (98%) rename service/{border/styles => style}/logo_melon_parameter.go (99%) rename service/{border/styles => style}/simple.go (99%) rename service/{border/styles => style}/simple_parameter.go (98%) rename service/{border => style}/styles_common/funcs.go (100%) rename service/{border/styles => style}/text_bottom.go (98%) rename service/{border/styles => style}/text_bottom_parameter.go (99%) diff --git a/README.md b/README.md index 58c96b5..0dd5ff0 100644 --- a/README.md +++ b/README.md @@ -32,37 +32,37 @@ $ go build add border with default parameters ```bash -$ capybara border simple +$ capybara style simple ``` using 'simple' style, with 100 border size, process 'input' folder images, save to 'output' folder ```bash -$ capybara border simple -w 100 -i input -o output +$ capybara style simple -w 100 -i input -o output ``` border color ```bash # with html color names, case-insensitive -$ capybara border --color AliceBlue +$ capybara style simple --color AliceBlue # with hex -$ capybara border --color "#228B22" +$ capybara style simple --color "#228B22" # with rgb -$ capybara border --color "rgb(238, 130, 238)" +$ capybara style simple --color "rgb(238, 130, 238)" # with rgba -$ capybara border --color "rgba(238, 130, 238, 255)" +$ capybara style simple --color "rgba(238, 130, 238, 255)" ``` ### Style Example ```bash -$ capybara border simple -$ capybara border text_bottom -$ capybara border melon +$ capybara style simple +$ capybara style text_bottom +$ capybara style melon ``` @@ -85,11 +85,11 @@ Different styles support different parameters. Please refer to the documentation You can use `subcommand --help` to view the default parameters. ```bash -$ ./capybara border text_bottom --help +$ ./capybara style text_bottom --help Style: Footer text, with photo exif Usage: - border border text_bottom [flags] + style style text_bottom [flags] Flags: -c, --color string specify border color (default "white") diff --git a/cmd/cmds_style.go b/cmd/cmds_style.go index 0594649..764c8b9 100644 --- a/cmd/cmds_style.go +++ b/cmd/cmds_style.go @@ -2,26 +2,26 @@ package cmd import ( "github.com/sincerefly/capybara/base/log" - "github.com/sincerefly/capybara/cmd/border" + "github.com/sincerefly/capybara/cmd/style" "github.com/spf13/cobra" ) func init() { - rootCmd.AddCommand(borderCmd) + rootCmd.AddCommand(styleCmd) - borderCmd.AddCommand(border.SimpleCmd) - borderCmd.AddCommand(border.TextBottomCmd) - borderCmd.AddCommand(border.LogoMelonCmd) + styleCmd.AddCommand(style.SimpleCmd) + styleCmd.AddCommand(style.TextBottomCmd) + styleCmd.AddCommand(style.LogoMelonCmd) } -var borderCmd = &cobra.Command{ - Use: "border", +var styleCmd = &cobra.Command{ + Use: "style", Short: "To batch add borders to images.", Run: func(cmd *cobra.Command, args []string) { if len(args) > 0 { - log.Warnf("border style '%s' unsupported", args[0]) + log.Warnf("style '%s' unsupported", args[0]) } else { - log.Warnf("border need subcommand, e.g., 'capybara border simple [parameter]'") + log.Warnf("style need subcommand, e.g., 'capybara style simple [parameter]'") } }, } diff --git a/cmd/border/logo_melon.go b/cmd/style/logo_melon.go similarity index 89% rename from cmd/border/logo_melon.go rename to cmd/style/logo_melon.go index d0de0f2..182895c 100644 --- a/cmd/border/logo_melon.go +++ b/cmd/style/logo_melon.go @@ -1,11 +1,10 @@ -package border +package style import ( "github.com/sincerefly/capybara/base/log" "github.com/sincerefly/capybara/cmd/border_common" "github.com/sincerefly/capybara/cmd/cmdutils" - "github.com/sincerefly/capybara/service/border" - "github.com/sincerefly/capybara/service/border/styles" + "github.com/sincerefly/capybara/service/style" "github.com/sincerefly/capybara/utils/colorizer" "github.com/spf13/cobra" ) @@ -15,7 +14,7 @@ var LogoMelonCmd = &cobra.Command{ Short: "Style: logo left, no padding", Run: func(cmd *cobra.Command, args []string) { - parameter := &styles.LogoMelonParameter{} + parameter := &style.LogoMelonParameter{} input := cmdutils.GetParam(cmd.Flags(), "input") parameter.SetInput(input) @@ -50,7 +49,7 @@ var LogoMelonCmd = &cobra.Command{ // run log.Debugf("parameter: %s", parameter.JSONString()) - border.NewStyleProcessor(border.StyleLogoMelon, parameter).Run() + style.NewStyleProcessor(style.StyleLogoMelon, parameter).Run() }, } diff --git a/cmd/border/simple.go b/cmd/style/simple.go similarity index 85% rename from cmd/border/simple.go rename to cmd/style/simple.go index ed341d8..e38ecc7 100644 --- a/cmd/border/simple.go +++ b/cmd/style/simple.go @@ -1,11 +1,10 @@ -package border +package style import ( "github.com/sincerefly/capybara/base/log" "github.com/sincerefly/capybara/cmd/border_common" "github.com/sincerefly/capybara/cmd/cmdutils" - "github.com/sincerefly/capybara/service/border" - "github.com/sincerefly/capybara/service/border/styles" + "github.com/sincerefly/capybara/service/style" "github.com/sincerefly/capybara/utils/colorizer" "github.com/spf13/cobra" ) @@ -15,7 +14,7 @@ var SimpleCmd = &cobra.Command{ Short: "Style: add a uniform-width border to the image.", Run: func(cmd *cobra.Command, args []string) { - parameter := &styles.SimpleParameter{} + parameter := &style.SimpleParameter{} input := cmdutils.GetParam(cmd.Flags(), "input") parameter.SetInput(input) @@ -41,7 +40,7 @@ var SimpleCmd = &cobra.Command{ // run log.Debugf("parameter: %s", parameter.JSONString()) - border.NewStyleProcessor(border.StyleSimple, parameter).Run() + style.NewStyleProcessor(style.StyleSimple, parameter).Run() }, } diff --git a/cmd/border/text_bottom.go b/cmd/style/text_bottom.go similarity index 88% rename from cmd/border/text_bottom.go rename to cmd/style/text_bottom.go index 4cb0301..bc87b1c 100644 --- a/cmd/border/text_bottom.go +++ b/cmd/style/text_bottom.go @@ -1,11 +1,10 @@ -package border +package style import ( "github.com/sincerefly/capybara/base/log" "github.com/sincerefly/capybara/cmd/border_common" "github.com/sincerefly/capybara/cmd/cmdutils" - "github.com/sincerefly/capybara/service/border" - "github.com/sincerefly/capybara/service/border/styles" + "github.com/sincerefly/capybara/service/style" "github.com/sincerefly/capybara/utils/colorizer" "github.com/spf13/cobra" ) @@ -15,7 +14,7 @@ var TextBottomCmd = &cobra.Command{ Short: "Style: Footer text, with photo exif", Run: func(cmd *cobra.Command, args []string) { - parameter := &styles.TextBottomParameter{} + parameter := &style.TextBottomParameter{} input := cmdutils.GetParam(cmd.Flags(), "input") parameter.SetInput(input) @@ -49,7 +48,7 @@ var TextBottomCmd = &cobra.Command{ // run log.Debugf("parameter: %s", parameter.JSONString()) - border.NewStyleProcessor(border.StyleTextBottom, parameter).Run() + style.NewStyleProcessor(style.StyleTextBottom, parameter).Run() }, } diff --git a/service/border/handler.go b/service/style/handler.go similarity index 85% rename from service/border/handler.go rename to service/style/handler.go index f8e1bee..161d7c3 100644 --- a/service/border/handler.go +++ b/service/style/handler.go @@ -1,10 +1,9 @@ -package border +package style import ( "fmt" "github.com/sincerefly/capybara/base/log" "github.com/sincerefly/capybara/constants" - "github.com/sincerefly/capybara/service/border/styles" "github.com/sincerefly/capybara/structure/fileitem" "github.com/sincerefly/capybara/utils/fsutil" "path/filepath" @@ -54,14 +53,14 @@ func (s *StyleProcessor) Run() { switch s.style { case StyleSimple: - params := s.params.(*styles.SimpleParameter) - err = styles.NewSimpleProcessor(params, fiStore).Run() + params := s.params.(*SimpleParameter) + err = NewSimpleProcessor(params, fiStore).Run() case StyleTextBottom: - params := s.params.(*styles.TextBottomParameter) - err = styles.NewTextBottomProcessor(params, fiStore).Run() + params := s.params.(*TextBottomParameter) + err = NewTextBottomProcessor(params, fiStore).Run() case StyleLogoMelon: - params := s.params.(*styles.LogoMelonParameter) - err = styles.NewLogoMelonProcessor(params, fiStore).Run() + params := s.params.(*LogoMelonParameter) + err = NewLogoMelonProcessor(params, fiStore).Run() } if err != nil { log.Fatal(err) diff --git a/service/border/styles/logo_melon.go b/service/style/logo_melon.go similarity index 98% rename from service/border/styles/logo_melon.go rename to service/style/logo_melon.go index 8901bcd..78a78b0 100644 --- a/service/border/styles/logo_melon.go +++ b/service/style/logo_melon.go @@ -1,4 +1,4 @@ -package styles +package style import ( "fmt" @@ -7,7 +7,7 @@ import ( "github.com/sincerefly/capybara/base/log" "github.com/sincerefly/capybara/global" "github.com/sincerefly/capybara/resources" - "github.com/sincerefly/capybara/service/border/styles_common" + "github.com/sincerefly/capybara/service/style/styles_common" "github.com/sincerefly/capybara/structure/fileitem" "github.com/sincerefly/capybara/structure/layout" "github.com/sincerefly/capybara/structure/size" diff --git a/service/border/styles/logo_melon_parameter.go b/service/style/logo_melon_parameter.go similarity index 99% rename from service/border/styles/logo_melon_parameter.go rename to service/style/logo_melon_parameter.go index 64146b6..2bd8525 100644 --- a/service/border/styles/logo_melon_parameter.go +++ b/service/style/logo_melon_parameter.go @@ -1,4 +1,4 @@ -package styles +package style import ( "encoding/json" diff --git a/service/border/styles/simple.go b/service/style/simple.go similarity index 99% rename from service/border/styles/simple.go rename to service/style/simple.go index ae902e7..528d885 100644 --- a/service/border/styles/simple.go +++ b/service/style/simple.go @@ -1,4 +1,4 @@ -package styles +package style import ( "github.com/disintegration/imaging" diff --git a/service/border/styles/simple_parameter.go b/service/style/simple_parameter.go similarity index 98% rename from service/border/styles/simple_parameter.go rename to service/style/simple_parameter.go index 1c4b89e..0bae8e5 100644 --- a/service/border/styles/simple_parameter.go +++ b/service/style/simple_parameter.go @@ -1,4 +1,4 @@ -package styles +package style import ( "encoding/json" diff --git a/service/border/styles_common/funcs.go b/service/style/styles_common/funcs.go similarity index 100% rename from service/border/styles_common/funcs.go rename to service/style/styles_common/funcs.go diff --git a/service/border/styles/text_bottom.go b/service/style/text_bottom.go similarity index 98% rename from service/border/styles/text_bottom.go rename to service/style/text_bottom.go index d051ba2..3127bf4 100644 --- a/service/border/styles/text_bottom.go +++ b/service/style/text_bottom.go @@ -1,4 +1,4 @@ -package styles +package style import ( "fmt" @@ -7,7 +7,7 @@ import ( "github.com/sincerefly/capybara/base/log" "github.com/sincerefly/capybara/global" "github.com/sincerefly/capybara/resources" - "github.com/sincerefly/capybara/service/border/styles_common" + "github.com/sincerefly/capybara/service/style/styles_common" "github.com/sincerefly/capybara/structure/fileitem" "github.com/sincerefly/capybara/structure/layout" "github.com/sincerefly/capybara/structure/size" diff --git a/service/border/styles/text_bottom_parameter.go b/service/style/text_bottom_parameter.go similarity index 99% rename from service/border/styles/text_bottom_parameter.go rename to service/style/text_bottom_parameter.go index 6445203..35a5c7c 100644 --- a/service/border/styles/text_bottom_parameter.go +++ b/service/style/text_bottom_parameter.go @@ -1,4 +1,4 @@ -package styles +package style import ( "encoding/json" From a1185715720a8fae5b524c6123d34c82903ec5e1 Mon Sep 17 00:00:00 2001 From: Yieldone Date: Fri, 26 Jul 2024 17:29:27 +0800 Subject: [PATCH 2/2] fix: exifviewer tool import --- tools/exifviewer/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/exifviewer/main.go b/tools/exifviewer/main.go index 7fd9984..f8d1a15 100644 --- a/tools/exifviewer/main.go +++ b/tools/exifviewer/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/sincerefly/capybara/service/border/styles_common" + "github.com/sincerefly/capybara/service/style/styles_common" "github.com/sincerefly/capybara/structure/fileitem" "os" "path/filepath"