Skip to content

Commit

Permalink
Update go version, actions and remove dependencies
Browse files Browse the repository at this point in the history
Start depending only on `x/term` instead of third-party dependencies.
Flags are changed, using the go standard library `flag` pkg.
  • Loading branch information
chrsmutti committed Mar 30, 2024
1 parent 6b8367f commit 52ddee0
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 83 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions .goreleaser.yml

This file was deleted.

29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...:
Expand All @@ -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 <normal_git_commands_here> -- <normal_git_flags_here>`
`git multi <git_multi_flags_here> <normal_git_commands_here> <normal_git_flags_here>`

## 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
Expand Down
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
32 changes: 10 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions repo.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package main

import (
"io/ioutil"
"os"
"os/exec"
"path"
)

// 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
}
Expand Down
5 changes: 3 additions & 2 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package main

import (
"fmt"
"os"
"strings"

terminal "github.com/wayneashleyberry/terminal-dimensions"
"golang.org/x/term"
)

type result struct {
Expand All @@ -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
}
Expand Down

0 comments on commit 52ddee0

Please sign in to comment.