diff --git a/context.go b/context.go index 9802594..0109f45 100644 --- a/context.go +++ b/context.go @@ -1,11 +1,14 @@ package cli import ( + "context" "errors" "flag" "os" + "os/signal" "reflect" "strings" + "syscall" ) // Context is a type that is passed through to @@ -13,6 +16,7 @@ import ( // can be used to retrieve context-specific args and // parsed command-line options. type Context struct { + context.Context App *App Command *Command shellComplete bool @@ -24,6 +28,14 @@ type Context struct { // NewContext creates a new context. For use in when invoking an App or Command action. func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context { c := &Context{App: app, flagSet: set, parentContext: parentCtx} + ctx, cancel := context.WithCancel(context.Background()) + go func() { + defer cancel() + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + <-sigs + }() + c.Context = ctx if parentCtx != nil { c.shellComplete = parentCtx.shellComplete diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7ee92dd --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module gopkg.in/urfave/fli.v2 + +go 1.12