Skip to content

Commit

Permalink
Issue 37/second try (#42)
Browse files Browse the repository at this point in the history
* Bump gitstatus to v0.4.3 (NewWithContext)

* Pass -timeout as ctx to gitstatus.NewWithContext
  • Loading branch information
arl authored Sep 2, 2020
1 parent 67343b2 commit 3983d85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions gitmux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -55,7 +56,7 @@ func (d *duration) Set(s string) error {
return nil
}

func parseOptions() (dir string, dbg bool, cfg Config) {
func parseOptions() (ctx context.Context, dir string, dbg bool, cfg Config) {
dbgOpt := flag.Bool("dbg", false, "")
cfgOpt := flag.String("cfg", "", "")
printCfgOpt := flag.Bool("printcfg", false, "")
Expand Down Expand Up @@ -97,12 +98,12 @@ func parseOptions() (dir string, dbg bool, cfg Config) {
check(dec.Decode(&cfg), *dbgOpt)
}

ctx = context.Background()
if timeout != 0 {
// Exit after the given amount of time
time.AfterFunc(time.Duration(timeout), func() { os.Exit(1) })
ctx, _ = context.WithTimeout(ctx, time.Duration(timeout))
}

return dir, *dbgOpt, cfg
return ctx, dir, *dbgOpt, cfg
}

func pushdir(dir string) (popdir func() error, err error) {
Expand Down Expand Up @@ -131,7 +132,7 @@ func check(err error, dbg bool) {
}

func main() {
dir, dbg, cfg := parseOptions()
ctx, dir, dbg, cfg := parseOptions()

// handle directory change.
if dir != "." {
Expand All @@ -144,7 +145,7 @@ func main() {
}

// retrieve git status.
st, err := gitstatus.New()
st, err := gitstatus.NewWithContext(ctx)
check(err, dbg)

// select defauit formater
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/arl/gitmux
go 1.10

require (
github.com/arl/gitstatus v0.4.2
github.com/arl/gitstatus v0.4.3
github.com/stretchr/testify v1.3.0
gopkg.in/yaml.v2 v2.2.4
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/arl/gitstatus v0.4.2 h1:PwUErrD3BV5E2wcbdvI2LewmWhDiFcRGwR6z4eGr0Bc=
github.com/arl/gitstatus v0.4.2/go.mod h1:pEiL+vLLz99X0m5G4MySAt4o0fQw2yUbFeq2s7sMUzY=
github.com/arl/gitstatus v0.4.3 h1:ad4Fk4uXRy7WRvK6UMKD1ijvElFN/ugvqzDWJo00pJs=
github.com/arl/gitstatus v0.4.3/go.mod h1:pEiL+vLLz99X0m5G4MySAt4o0fQw2yUbFeq2s7sMUzY=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down

0 comments on commit 3983d85

Please sign in to comment.