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

refactor: rename sub-cmd 'border' to 'style' #2

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
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
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

<table>
Expand All @@ -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")
Expand Down
18 changes: 9 additions & 9 deletions cmd/cmds_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]'")
}
},
}
9 changes: 4 additions & 5 deletions cmd/border/logo_melon.go → cmd/style/logo_melon.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
},
}

Expand Down
9 changes: 4 additions & 5 deletions cmd/border/simple.go → cmd/style/simple.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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)
Expand All @@ -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()
},
}

Expand Down
9 changes: 4 additions & 5 deletions cmd/border/text_bottom.go → cmd/style/text_bottom.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
},
}

Expand Down
15 changes: 7 additions & 8 deletions service/border/handler.go → service/style/handler.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package styles
package style

import (
"fmt"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package styles
package style

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package styles
package style

import (
"github.com/disintegration/imaging"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package styles
package style

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package styles
package style

import (
"fmt"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package styles
package style

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion tools/exifviewer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading