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

36
env/constants.go vendored Normal file
View file

@ -0,0 +1,36 @@
package env
import (
"os"
"path/filepath"
"github.com/FAU-CDI/wisski-distillery/internal/fsx"
)
// Executable is the name of the 'wdcli' executable.
// It should be located inside the deployment directory.
const Executable = "wdcli"
// ExecutablePath returns the path to the executable of this distillery.
func (dis *Distillery) ExecutablePath() string {
return filepath.Join(dis.Config.DeployRoot, Executable)
}
// UsingDistilleryExecutable checks if the current process
func (dis *Distillery) UsingDistilleryExecutable() bool {
exe, err := os.Executable()
if err != nil {
return false
}
return fsx.SameFile(exe, dis.ExecutablePath())
}
// Config file is the name of the config file.
// It should be located inside the deployment directory.
const ConfigFile = ".env"
// ConfigFilePath returns the path to the configuration file of this distillery.
// TODO: This should be moved to the Config struct.
func (dis *Distillery) ConfigFilePath() string {
return filepath.Join(dis.Config.DeployRoot, ConfigFile)
}

2
env/distillery.go vendored
View file

@ -54,7 +54,7 @@ func NewDistillery(params Params, req Requirements) (env *Distillery, err error)
env = &Distillery{}
// if we don't need to load the config, there is nothing to do
if !req.NeedsConfig {
if !req.NeedsDistillery {
return
}

2
env/params.go vendored
View file

@ -20,7 +20,7 @@ func (params Params) ConfigFilePath() string {
if params.BaseDirectory == "" {
return ""
}
return filepath.Join(params.BaseDirectory, ".env")
return filepath.Join(params.BaseDirectory, ConfigFile)
}
var errUnableToLoadParams = exit.Error{

3
env/requirements.go vendored
View file

@ -6,7 +6,8 @@ import (
)
type Requirements struct {
NeedsConfig bool
// Do we need an installed distillery?
NeedsDistillery bool
}
// AllowsFlag checks if the provided flag may be passed to fullfill this requirement