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

feat: バージョン表示に対応 #10

Merged
merged 4 commits into from
Nov 13, 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
1 change: 1 addition & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.merged == true && github.base_ref || github.event.pull_request.head.sha }}

- name: 🏷️ Bump version and push tag
id: tag-version
Expand Down
2 changes: 1 addition & 1 deletion cmd/splashscreen-changer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"strconv"
"strings"

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

Check failure on line 10 in cmd/splashscreen-changer/config.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package gopkg.in/yaml.v2; to add it:
)

type Config struct {
Expand Down
28 changes: 23 additions & 5 deletions cmd/splashscreen-changer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@ func cropToAspectRatio(img image.Image, width, height int) image.Image {
cropRect = image.Rect(0, y0, srcWidth, y0+newHeight)
}

return img.(interface {
// 指定された範囲を切り取る
croppedImg := img.(interface {
SubImage(r image.Rectangle) image.Image
}).SubImage(cropRect)

// 切り取った画像を指定のサイズにリサイズ
dst := image.NewRGBA(image.Rect(0, 0, width, height))
draw.Draw(dst, dst.Bounds(), croppedImg, croppedImg.Bounds().Min, draw.Src)

return dst
}

// PNGファイルをリサイズする関数
Expand Down Expand Up @@ -129,9 +136,9 @@ func resizePNGFile(srcPath, destPath string, width, height int) error {
func printHelp() {
fmt.Println("Usage: splashscreen-changer [options]")
fmt.Println("Options:")
fmt.Println(" --help, -h Show this help message")
flag.PrintDefaults()
fmt.Println("Environment Variables:")
fmt.Println(" CONFIG_PATH Path to the configuration file (default: config.yaml)")
fmt.Printf(" %-20s %s\n", "CONFIG_PATH", "Path to the configuration file (default: config.yaml)")

// Config 構造体のフィールドから環境変数のキーを生成して表示
configType := reflect.TypeOf(Config{})
Expand All @@ -146,20 +153,31 @@ func printHelp() {
fmt.Printf(" %-20s %s\n", envKey, helpTag)
}
}

fmt.Println()
fmt.Println("GitHub: https://github.com/tomacheese/splashscreen-changer")
}

func main() {
// コマンドライン引数を解析する
helpFlag := flag.Bool("help", false, "Show help message")
hFlag := flag.Bool("h", false, "Show help message")
vFlag := flag.Bool("v", false, "Show version")
flag.Parse()

// ヘルプメッセージを表示する
if *helpFlag || *hFlag {
if *hFlag {
printHelp()
return
}

// バージョン情報を表示する
if *vFlag {
fmt.Println("splashscreen-changer")
fmt.Println("|- Version", GetAppVersion())
fmt.Println("|- Build date:", GetAppDate())
return
}

// 設定ファイルを読み込む。設定ファイルパスは環境変数 CONFIG_PATH で指定し、指定されていない場合は "config.yaml" とする。
configPath := os.Getenv("CONFIG_PATH")
if configPath == "" {
Expand Down
28 changes: 28 additions & 0 deletions cmd/splashscreen-changer/versioning.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"runtime/debug"
)

var version string
var date string

func GetAppVersion() string {
if version != "" {
return version
}

if buildInfo, ok := debug.ReadBuildInfo(); ok {
return buildInfo.Main.Version
}

return "unknown"
}

func GetAppDate() string {
if date != "" {
return date
}

return "unknown"
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ require (
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
golang.org/x/image v0.22.0
gopkg.in/yaml.v3 v3.0.1
gopkg.in/yaml.v3 v3.0.1
)
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ golang.org/x/image v0.22.0 h1:UtK5yLUzilVrkjMAZAZ34DXGpASN8i8pj8g+O+yd10g=
golang.org/x/image v0.22.0/go.mod h1:9hPFhljd4zZ1GNSIZJ49sqbp45GKK9t6w+iXvGqZUz4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading