-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add initial feature implementation (#1)
- Main feature implementation - Test github workflow
- Loading branch information
Showing
19 changed files
with
880 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Build and Upload Binaries on Tag | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' # Trigger the workflow for tags like v1.0, v2.1, etc. | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Checkout the code | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
# Set up Go environment | ||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '1.21' # Set the Go version you're using | ||
|
||
# Get the version from the tag | ||
- name: Get version from tag | ||
id: get_version | ||
run: | | ||
echo "VERSION=$(echo ${GITHUB_REF} | sed 's/refs\/tags\///')" >> $GITHUB_ENV | ||
# Get the repository name from the GitHub context (e.g., steam-utils from bearaujus/steam-utils) | ||
- name: Get repo name | ||
id: get_repo_name | ||
run: | | ||
REPO_NAME=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f2) | ||
echo "REPO_NAME=${REPO_NAME}" >> $GITHUB_ENV | ||
# Build binaries for all GOOS and GOARCH combinations | ||
- name: Build binaries | ||
run: | | ||
# List of GOOS and GOARCH combinations | ||
GOOS_ARCH_LIST=$(go tool dist list) | ||
VERSION=${{ env.VERSION }} | ||
REPO_NAME=${{ env.REPO_NAME }} | ||
# Create a directory for the build outputs | ||
mkdir -p binaries | ||
# Loop through the GOOS and GOARCH combinations and build binaries | ||
for GOOS_ARCH in $GOOS_ARCH_LIST; do | ||
GOOS=$(echo $GOOS_ARCH | cut -d'/' -f1) | ||
GOARCH=$(echo $GOOS_ARCH | cut -d'/' -f2) | ||
# Set environment variables | ||
export GOOS | ||
export GOARCH | ||
# Build the binary with the required format and ldflags for version, name, arch, and goos | ||
FILENAME="${REPO_NAME}-${VERSION}-${GOOS}-${GOARCH}" | ||
go build -ldflags "-X main.name=${REPO_NAME} -X main.version=${VERSION} -X main.arch=${GOARCH} -X main.goos=${GOOS}" -o "binaries/${FILENAME}" | ||
echo "Built binary: ${FILENAME}" | ||
done | ||
# Upload binaries to GitHub Releases | ||
- name: Upload binaries to release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: binaries/* | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ | |
*.dll | ||
*.so | ||
*.dylib | ||
**/.idea | ||
**/.DS_Store | ||
dev | ||
bin | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module github.com/bearaujus/steam-utils | ||
|
||
go 1.23.3 | ||
|
||
require ( | ||
github.com/bearaujus/berror v0.0.1 | ||
github.com/spf13/cobra v1.8.1 | ||
) | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
github.com/bearaujus/berror v0.0.1 h1:O7/b0SvDQMNHjUmERiGKzvGmpudvhJFd5nuYtMCtz1g= | ||
github.com/bearaujus/berror v0.0.1/go.mod h1:gqwSzaF6jOE3pCU8x2JXt8+j5ns72G6OWunartoQJcw= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= | ||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"github.com/bearaujus/steam-utils/internal/cli/library" | ||
"github.com/bearaujus/steam-utils/internal/config" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewRoot(ctx context.Context, cfg *config.Config) *cobra.Command { | ||
var rootCmd = &cobra.Command{ | ||
Use: "steam-utils", | ||
Short: "Sets of utilities for managing your Steam", | ||
Args: cobra.NoArgs, | ||
CompletionOptions: cobra.CompletionOptions{ | ||
DisableDefaultCmd: true, | ||
DisableNoDescFlag: true, | ||
DisableDescriptions: true, | ||
HiddenDefaultCmd: true, | ||
}, | ||
} | ||
rootCmd.AddCommand(newLibraryCmd(ctx, cfg)) | ||
return rootCmd | ||
} | ||
|
||
func newLibraryCmd(ctx context.Context, cfg *config.Config) *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "library", | ||
Short: "Steam library utilities", | ||
Args: cobra.NoArgs, | ||
} | ||
for _, childCmd := range library.New(ctx, cfg) { | ||
cmd.AddCommand(childCmd) | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package library | ||
|
||
import ( | ||
"context" | ||
"github.com/bearaujus/steam-utils/internal/cli/library/set_auto_update" | ||
"github.com/bearaujus/steam-utils/internal/cli/library/set_background_downloads" | ||
"github.com/bearaujus/steam-utils/internal/config" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func New(ctx context.Context, cfg *config.Config) []*cobra.Command { | ||
return []*cobra.Command{ | ||
newSetAutoUpdateCmd(ctx, cfg), | ||
newSetBackgroundDownloadsCmd(ctx, cfg), | ||
} | ||
} | ||
|
||
func newSetAutoUpdateCmd(ctx context.Context, cfg *config.Config) *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "set-auto-update", | ||
Short: "Set auto update behavior on all collections on your Steam library", | ||
Args: cobra.NoArgs, | ||
} | ||
for _, childCmd := range set_auto_update.New(ctx, cfg) { | ||
cmd.AddCommand(childCmd) | ||
} | ||
return cmd | ||
} | ||
|
||
func newSetBackgroundDownloadsCmd(ctx context.Context, cfg *config.Config) *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "set-background-downloads", | ||
Short: "Set background downloads behavior on all collections on your Steam library", | ||
Args: cobra.NoArgs, | ||
} | ||
for _, childCmd := range set_background_downloads.New(ctx, cfg) { | ||
cmd.AddCommand(childCmd) | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package set_auto_update | ||
|
||
import ( | ||
"context" | ||
"github.com/bearaujus/steam-utils/internal/config" | ||
"github.com/bearaujus/steam-utils/internal/usecase/library/set_auto_update" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func New(ctx context.Context, cfg *config.Config) []*cobra.Command { | ||
return []*cobra.Command{ | ||
new0Cmd(ctx, cfg), | ||
new1Cmd(ctx, cfg), | ||
} | ||
} | ||
|
||
func new0Cmd(ctx context.Context, cfg *config.Config) *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "0", | ||
Short: "Always keep all games updated", | ||
Args: cobra.NoArgs, | ||
RunE: set_auto_update.NewCmdRunner(ctx, cfg), | ||
} | ||
return cmd | ||
} | ||
|
||
func new1Cmd(ctx context.Context, cfg *config.Config) *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "1", | ||
Short: "Only update a game when you launch it", | ||
Args: cobra.NoArgs, | ||
RunE: set_auto_update.NewCmdRunner(ctx, cfg), | ||
} | ||
return cmd | ||
} |
46 changes: 46 additions & 0 deletions
46
internal/cli/library/set_background_downloads/set_background_downloads.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package set_background_downloads | ||
|
||
import ( | ||
"context" | ||
"github.com/bearaujus/steam-utils/internal/config" | ||
"github.com/bearaujus/steam-utils/internal/usecase/library/set_background_downloads" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func New(ctx context.Context, cfg *config.Config) []*cobra.Command { | ||
return []*cobra.Command{ | ||
new0Cmd(ctx, cfg), | ||
new1Cmd(ctx, cfg), | ||
new2Cmd(ctx, cfg), | ||
} | ||
} | ||
|
||
func new0Cmd(ctx context.Context, cfg *config.Config) *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "0", | ||
Short: "Follow your global steam settings", | ||
Args: cobra.NoArgs, | ||
RunE: set_background_downloads.NewCmdRunner(ctx, cfg), | ||
} | ||
return cmd | ||
} | ||
|
||
func new1Cmd(ctx context.Context, cfg *config.Config) *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "1", | ||
Short: "Always allow background downloads", | ||
Args: cobra.NoArgs, | ||
RunE: set_background_downloads.NewCmdRunner(ctx, cfg), | ||
} | ||
return cmd | ||
} | ||
|
||
func new2Cmd(ctx context.Context, cfg *config.Config) *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "2", | ||
Short: "Never allow background downloads", | ||
Args: cobra.NoArgs, | ||
RunE: set_background_downloads.NewCmdRunner(ctx, cfg), | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/bearaujus/steam-utils/pkg/steam_path" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
PersistentFlagSteamPath = "steam-path" | ||
) | ||
|
||
type Config struct { | ||
SteamPath string | ||
} | ||
|
||
func LoadConfig(cmd *cobra.Command, config *Config) error { | ||
var defaultSteamPath string | ||
sp, err := steam_path.LoadDefaultSteamPath() | ||
if err == nil { | ||
defaultSteamPath = sp.Base() | ||
} | ||
cmd.PersistentFlags().StringVar(&config.SteamPath, PersistentFlagSteamPath, defaultSteamPath, "Path to steam installation directory") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package model | ||
|
||
import ( | ||
"github.com/bearaujus/berror" | ||
) | ||
|
||
var ( | ||
ErrSteamPathIsNotSet = berror.NewErrDefinition("default steam installation path is not detected. please include flag '--%v'", berror.OptionErrDefinitionWithDisabledStackTrace()) | ||
ErrSteamPathIsInvalid = berror.NewErrDefinition("%v. please update argument on flag '--%v'", berror.OptionErrDefinitionWithDisabledStackTrace()) | ||
ErrReadDirectory = berror.NewErrDefinition("fail to read directory: %v", berror.OptionErrDefinitionWithDisabledStackTrace()) | ||
ErrReadFile = berror.NewErrDefinition("fail to read file: %v", berror.OptionErrDefinitionWithDisabledStackTrace()) | ||
ErrWriteFile = berror.NewErrDefinition("fail to write file: %v", berror.OptionErrDefinitionWithDisabledStackTrace()) | ||
ErrParseSteamACFFile = berror.NewErrDefinition("fail to parse steam acf: %v", berror.OptionErrDefinitionWithDisabledStackTrace()) | ||
ErrGetValueFromSteamACFFile = berror.NewErrDefinition("fail to get value from steam acf: %v", berror.OptionErrDefinitionWithDisabledStackTrace()) | ||
ErrUpdateValueFromSteamACFFile = berror.NewErrDefinition("fail to update value to steam acf: %v", berror.OptionErrDefinitionWithDisabledStackTrace()) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package pkg | ||
|
||
import "fmt" | ||
|
||
func PrintSep() { | ||
fmt.Println("-------------------------------------------------------------------------------------------------") | ||
} |
Oops, something went wrong.