func cleanup(cmd *cobra.Command) {
	sig.Signal.ResetCleanups()
	cmd.LocalFlags().VisitAll(func(f *pflag.Flag) { f.Changed = false })
	cmd.Flags().Set("help", "false")
}
cleanup resets signal cleanups and sets all flags as unchanged to keep using default values.

It also sets the help flag internal variable to false in case it's used.
package session
import (
	"bufio"
	"fmt"
	"io"
	"os"
	"runtime"
	"strings"
	"time"
	"github.com/GGP1/kure/auth"
	cmdutil "github.com/GGP1/kure/commands"
	"github.com/GGP1/kure/config"
	"github.com/GGP1/kure/sig"
	"github.com/spf13/cobra"
	"github.com/spf13/pflag"
	bolt "go.etcd.io/bbolt"
)
var example = `
* Run a session without timeout and using "$" as the prefix
kure session -p $
* Run a session for 1 hour
kure session -t 1h`
type sessionOptions struct {
	prefix  string
	timeout time.Duration
}
type timeout struct {
	t     time.Duration
	start time.Time
	timer *time.Timer
}
func NewCmd(db *bolt.DB, r io.Reader) *cobra.Command {
	opts := sessionOptions{}
	cmd := &cobra.Command{
		Use:   "session",
		Short: "Run a session",
		Long: `Sessions let you do multiple operations by providing the master password once. 
They support running scripts using the logical AND (&&) operator and executing pre-defined ones from the configuration file by using their aliases.
During a session, the master password is encrypted and stored inside a protected buffer.
Session commands:
• block - block execution (to be manually unlocked).
• exit|quit|Ctrl+C - close the session.
• pwd - show current directory.
• timeout - show time left.
• ttadd [duration] - increase/decrease timeout.
• ttset [duration] - set a new timeout.
• sleep [duration] - sleep for x time.`,
		Example: example,
		PreRunE: auth.Login(db),
		RunE:    runSession(r, &opts),
	}
	f := cmd.Flags()
	f.StringVarP(&opts.prefix, "prefix", "p", "kure:~ $", "text that precedes your commands")
	f.DurationVarP(&opts.timeout, "timeout", "t", 0, "session timeout")
	return cmd
}
func runSession(r io.Reader, opts *sessionOptions) cmdutil.RunEFunc {
	return func(cmd *cobra.Command, args []string) error {
		if p := "session.prefix"; config.IsSet(p) && !cmd.Flags().Changed("prefix") {
			opts.prefix = config.GetString(p)
		}
		if t := "session.timeout"; config.IsSet(t) && !cmd.Flags().Changed("timeout") {
			opts.timeout = config.GetDuration(t)
		}
		timeout := &timeout{
			t:     opts.timeout,
			start: time.Now(),
			timer: time.NewTimer(opts.timeout),
		}
		go startSession(cmd, r, opts.prefix, timeout)
		if timeout.t == 0 {
			if !timeout.timer.Stop() {
				<-timeout.timer.C
			}
		}
		<-timeout.timer.C
		return nil
	}
}
func startSession(cmd *cobra.Command, r io.Reader, prefix string, timeout *timeout) {
	reader := bufio.NewReader(r)
	root := cmd.Root()
	scripts := config.GetStringMapString("session.scripts")
	for {
		runtime.GC()
		fmt.Printf("%s ", prefix)
		text, _, err := reader.ReadLine()
		if err != nil {
			if err == io.EOF {
				sig.Signal.Kill()
			}
			fmt.Fprintln(os.Stderr, "error:", err)
			continue
		}
		args := strings.Split(string(text), " ")
		script, ok := scripts[args[0]]
		if ok {
			script = fillScript(args[1:], script)
			args = strings.Split(script, " ")
		}
		if err := execute(root, args, timeout); err != nil {
			fmt.Fprintln(os.Stderr, "error:", err)
		}
	}
}