github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/prog/flags.go (about)

     1  package prog
     2  
     3  import "flag"
     4  
     5  type FlagSet struct {
     6  	*flag.FlagSet
     7  	daemonPaths *DaemonPaths
     8  	json        *bool
     9  }
    10  
    11  type DaemonPaths struct {
    12  	DB, Sock string
    13  }
    14  
    15  func (fs *FlagSet) DaemonPaths() *DaemonPaths {
    16  	if fs.daemonPaths == nil {
    17  		var dp DaemonPaths
    18  		fs.StringVar(&dp.DB, "db", "", "[internal flag] path to the database")
    19  		fs.StringVar(&dp.Sock, "sock", "", "[internal flag] path to the daemon socket")
    20  		fs.daemonPaths = &dp
    21  	}
    22  	return fs.daemonPaths
    23  }
    24  
    25  func (fs *FlagSet) JSON() *bool {
    26  	if fs.json == nil {
    27  		var json bool
    28  		fs.BoolVar(&json, "json", false, "show output in JSON. Useful with -buildinfo and -compileonly")
    29  		fs.json = &json
    30  	}
    31  	return fs.json
    32  }