Documentation ¶
Index ¶
- func CallSudo(action SudoAction) error
- func CliChoice(question string, choices []string) (int, error)
- func CliQuestion(question string) string
- func CliQuestionHidden(question string) (string, error)
- func CliQuestionYesNo(question string) bool
- func CliQuestionYesNoDefault(question string, defaultValue bool) bool
- func GetAutoUpdate(configDir *UserConfigDir) (bool, error)
- func LoadExternalConfig(filename string, data interface{}) error
- func RegisterAction(action SudoAction)
- func SaveExternalConfig(filename string, data interface{}) error
- func SetAutoUpdate(configDir *UserConfigDir, shouldAutoUpdate bool) (bool, error)
- func TryHandleSudo()
- type AutoUpdater
- type ReplaceExecutableSudoAction
- type SudoAction
- type UserConfigDir
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallSudo ¶
func CallSudo(action SudoAction) error
CallSudo asks the user for superuser permissions, and then executes the currently-running program with those permissions for a particular action. TryHandleSudo should be called at the beginning of the program's main() function to catch these sudo calls.
func CliQuestion ¶
CliQuestion prints a prompt to stdout and reads a line of input from stdin, returning that read string
func CliQuestionHidden ¶
CliQuestionHidden prints a prompt to stdout and reads a hidden line of input from stdin. This is meant to be used for passwords where you don't want them printed to the screen
func CliQuestionYesNo ¶
CliQuestionYesNo prints a question prompt and allows either yes or no answers to be entered, returning "y" or "yes" as true and "n" or "no" as false
func CliQuestionYesNoDefault ¶
CliQuestionYesNoDefault prints a question prompt and allows either yes or no answers to be entered, or no answer at all. If no answer is entered, the defaultValue is returned, otherwise "y" or "yes" returns true and "n" or "no" returns false
func GetAutoUpdate ¶
func GetAutoUpdate(configDir *UserConfigDir) (bool, error)
GetAutoUpdate gets if automatic updates are enabled
func LoadExternalConfig ¶
LoadExternalConfig reads an external config file, outside of the default user config directory
func RegisterAction ¶
func RegisterAction(action SudoAction)
func SaveExternalConfig ¶
SaveExternalConfig saves a file outside of the default user config directory
func SetAutoUpdate ¶
func SetAutoUpdate(configDir *UserConfigDir, shouldAutoUpdate bool) (bool, error)
SetAutoUpdate configures if automatic updates are enabled
func TryHandleSudo ¶
func TryHandleSudo()
TryHandleSudo catches superuser self-executions to do certain actions that require superuser permissions
Types ¶
type AutoUpdater ¶
type AutoUpdater struct {
// contains filtered or unexported fields
}
func NewAutoUpdater ¶
func NewAutoUpdater( configDir *UserConfigDir, buildVersion, githubRepo string, isPrivate bool, configSubcommand *string, ) (*AutoUpdater, error)
func (*AutoUpdater) TryAutoUpdateSelf ¶
func (updater *AutoUpdater) TryAutoUpdateSelf() error
TryAutoUpdateSelf checks for an update and replaces the existing executable with the new version if there is one. Update checks are debounced to every 24 hours, and can be disabled with a config option.
func (*AutoUpdater) TryManualUpdate ¶
func (updater *AutoUpdater) TryManualUpdate() error
TryManualUpdate checks for an update and replaces the existing executable with the new version if there is one. This will always run, without any debouncing or config options to disable it.
type ReplaceExecutableSudoAction ¶
type ReplaceExecutableSudoAction struct {
NewExe string
}
func (ReplaceExecutableSudoAction) Handle ¶
func (a ReplaceExecutableSudoAction) Handle(params []string) error
func (ReplaceExecutableSudoAction) Name ¶
func (a ReplaceExecutableSudoAction) Name() string
func (ReplaceExecutableSudoAction) Params ¶
func (a ReplaceExecutableSudoAction) Params() []string
type SudoAction ¶
type UserConfigDir ¶
type UserConfigDir struct {
// contains filtered or unexported fields
}
func NewUserConfigDir ¶
func NewUserConfigDir(name string) *UserConfigDir
func (*UserConfigDir) GetConfigDir ¶
func (userConfigDir *UserConfigDir) GetConfigDir() (string, error)
GetConfigDir gets the os-dependent user configuration directory
func (*UserConfigDir) LoadConfig ¶
func (userConfigDir *UserConfigDir) LoadConfig(config string, data interface{}) error
LoadConfig loads a user config file of the given name
func (*UserConfigDir) SaveConfig ¶
func (userConfigDir *UserConfigDir) SaveConfig(config string, data interface{}) error
SaveConfig saves a user config file of the given name