Show a warning when using wrong executable

This commit updates the 'wdcli' command to show a warning when using the
wrong executable.
This commit is contained in:
Tom Wiesing 2022-09-09 13:35:02 +02:00
parent c4de1f2a06
commit 35bb95c5ca
No known key found for this signature in database
29 changed files with 176 additions and 30 deletions

View file

@ -27,13 +27,25 @@ var errUserIsNotRoot = exit.Error{
Message: "This command has to be executed as root. The current user is not root.",
}
var warnNoDeployWdcli = "Warning: Not using %q executable at %q. This might leave the distillery in an inconsistent state. \n"
func NewProgram() Program {
return Program{
BeforeCommand: func(context Context, command Command) error {
// make sure that we are root!
usr, err := user.Current()
if err != nil || usr.Uid != "0" || usr.Gid != "0" { // make sure that we are root!
if err != nil || usr.Uid != "0" || usr.Gid != "0" {
return errUserIsNotRoot
}
// warn when not using the distillery excutable
if context.Description.Requirements.NeedsDistillery {
dis := context.Environment
if !dis.UsingDistilleryExecutable() {
context.EPrintf(warnNoDeployWdcli, env.Executable, dis.ExecutablePath())
}
}
return nil
},