From 52ddee0975a8f574d75328f0ee91b1a66c124735 Mon Sep 17 00:00:00 2001 From: Christian Mutti Date: Sat, 30 Mar 2024 09:30:03 -0300 Subject: [PATCH] Update go version, actions and remove dependencies Start depending only on `x/term` instead of third-party dependencies. Flags are changed, using the go standard library `flag` pkg. --- .github/workflows/go.yml | 12 ++++-------- .goreleaser.yml | 23 ----------------------- README.md | 29 +++++++++++++---------------- go.mod | 9 ++++----- go.sum | 8 ++++---- main.go | 32 ++++++++++---------------------- repo.go | 5 ++--- run.go | 5 +++-- 8 files changed, 40 insertions(+), 83 deletions(-) delete mode 100644 .goreleaser.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 68d10c0..bec9411 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -8,17 +8,13 @@ jobs: goreleaser: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 - uses: actions/setup-go@v1 + - uses: actions/checkout@v1 + - uses: actions/setup-go@v5 with: - go-version: 1.13 - id: go - - - name: Checkout - uses: actions/checkout@v1 + go-version: 'stable' - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v1 + uses: goreleaser/goreleaser-action@v5 with: version: latest args: release diff --git a/.goreleaser.yml b/.goreleaser.yml deleted file mode 100644 index ca0f310..0000000 --- a/.goreleaser.yml +++ /dev/null @@ -1,23 +0,0 @@ -before: - hooks: - - go mod tidy -builds: - - env: - - CGO_ENABLED=0 -archives: - - replacements: - darwin: Darwin - linux: Linux - windows: Windows - 386: i386 - amd64: x86_64 -checksum: - name_template: "checksums.txt" -snapshot: - name_template: "{{ .Tag }}-next" -changelog: - sort: asc - filters: - exclude: - - "^docs:" - - "^test:" diff --git a/README.md b/README.md index 3abf2fa..59f0fb5 100644 --- a/README.md +++ b/README.md @@ -34,18 +34,15 @@ make install ## Usage ``` -Usage: - git-multi [OPTIONS] - -Application Options: - -w, --working-dir= set the working directory (default: .) - --no-group do not group same outputs - -d, --depth= depth of folders to look into for git repositories - (default: 1) - --no-color do not print color characters - -Help Options: - -h, --help Show this help message +Usage of git-multi: + -d int + depth of folders to look into for git repositories (default 1) + -no-color + do not print color characters + -no-group + do not group same outputs + -w string + set the working directory (default ".") ``` If you have repositories ~/Projects/Repo1, ~/Projects/Repo2, ...: @@ -60,19 +57,19 @@ git multi status git multi # You can also pass flags to git commands: -git multi status -- --short +git multi status --short ``` The basic usage is simple: -`git multi -- ` +`git multi ` ## Group By Output By default this version of git multi always groups by output, if that's not what -you desire you can use the `--no-group` flag. +you desire you can use the `-no-group` flag. ``` -git multi --no-group +git multi -no-group ``` # License diff --git a/go.mod b/go.mod index b505f20..a6fb0dc 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,7 @@ module github.com/chrsmutti/git-multi -go 1.12 +go 1.22 -require ( - github.com/jessevdk/go-flags v1.4.1-0.20181221193153-c0795c8afcf4 - github.com/wayneashleyberry/terminal-dimensions v1.0.0 -) +require golang.org/x/term v0.18.0 + +require golang.org/x/sys v0.18.0 // indirect diff --git a/go.sum b/go.sum index dee2e62..e674772 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -github.com/jessevdk/go-flags v1.4.1-0.20181221193153-c0795c8afcf4 h1:xKkUL6QBojwguhKKetf1SocCAKqc6W7S/mGm9xEGllo= -github.com/jessevdk/go-flags v1.4.1-0.20181221193153-c0795c8afcf4/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/wayneashleyberry/terminal-dimensions v1.0.0 h1:LawtS1nqKjAfqrmKOzkcrDLAjSzh38lEhC401JPjQVA= -github.com/wayneashleyberry/terminal-dimensions v1.0.0/go.mod h1:PW2XrtV6KmKOPhuf7wbtcmw1/IFnC39mryRET2XbxeE= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= diff --git a/main.go b/main.go index 2b6b4aa..b0e59a8 100644 --- a/main.go +++ b/main.go @@ -1,42 +1,30 @@ package main import ( + "flag" "fmt" "os" "path" "strings" - - "github.com/jessevdk/go-flags" ) -var opts struct { - WorkingDir string `short:"w" long:"working-dir" default:"." description:"set the working directory"` - NoGroup bool `long:"no-group" description:"do not group same outputs"` - Depth int `short:"d" long:"depth" default:"1" description:"depth of folders to look into for git repositories"` - NoColor bool `long:"no-color" description:"do not print color characters"` -} +var workingDir = flag.String("w", ".", "set the working directory") +var depth = flag.Int("d", 1, "depth of folders to look into for git repositories") +var noGroup = flag.Bool("no-group", false, "do not group same outputs") +var noColor = flag.Bool("no-color", false, "do not print color characters") func main() { - parser := flags.NewParser(&opts, flags.Default) - - commands, err := parser.Parse() - if err != nil { - if !flags.WroteHelp(err) { - parser.WriteHelp(os.Stderr) - } - - os.Exit(1) - } - - opts.WorkingDir = path.Clean(opts.WorkingDir) + flag.Parse() + var commands = flag.Args() + var workingDir = path.Clean(*workingDir) - repos, err := Repos(opts.WorkingDir, 1, opts.Depth) + repos, err := Repos(workingDir, 1, *depth) if err != nil { fmt.Fprintf(os.Stderr, "failed to get git repos: %v\n", err) os.Exit(1) } - if err = run(commands, repos, opts.WorkingDir, !opts.NoGroup, !opts.NoColor); err != nil { + if err = run(commands, repos, workingDir, !*noGroup, !*noColor); err != nil { fmt.Fprintf(os.Stderr, "failed to run git %s: %v\n", strings.Join(commands, " "), err) os.Exit(1) } diff --git a/repo.go b/repo.go index 8c1c328..dabf985 100644 --- a/repo.go +++ b/repo.go @@ -1,7 +1,6 @@ package main import ( - "io/ioutil" "os" "os/exec" "path" @@ -9,14 +8,14 @@ import ( // Repo contains information about a git repository. type Repo struct { - os.FileInfo + os.DirEntry // Path is the relative path to the repo from the working dir. Path string } // Repos returns all git repositories present in a directory. func Repos(dir string, current int, depth int) ([]Repo, error) { - items, err := ioutil.ReadDir(dir) + items, err := os.ReadDir(dir) if err != nil { return nil, err } diff --git a/run.go b/run.go index bc8df98..45aa652 100644 --- a/run.go +++ b/run.go @@ -2,9 +2,10 @@ package main import ( "fmt" + "os" "strings" - terminal "github.com/wayneashleyberry/terminal-dimensions" + "golang.org/x/term" ) type result struct { @@ -18,7 +19,7 @@ func run(commands []string, repos []Repo, dir string, group bool, color bool) er commands = []string{"status"} } - w, err := terminal.Width() + w, _, err := term.GetSize(int(os.Stdin.Fd())) if err != nil { return err }