diff --git a/gitmux.go b/gitmux.go index 5df5c05..25a250e 100644 --- a/gitmux.go +++ b/gitmux.go @@ -1,6 +1,7 @@ package main import ( + "context" "flag" "fmt" "os" @@ -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, "") @@ -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) { @@ -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 != "." { @@ -144,7 +145,7 @@ func main() { } // retrieve git status. - st, err := gitstatus.New() + st, err := gitstatus.NewWithContext(ctx) check(err, dbg) // select defauit formater diff --git a/go.mod b/go.mod index 83f617c..09cd089 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index a2ba2b4..c8811bc 100644 --- a/go.sum +++ b/go.sum @@ -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=