diff --git a/configs/ubuntu.yml b/configs/ubuntu.yml index ec5e0bd..1cf8b78 100644 --- a/configs/ubuntu.yml +++ b/configs/ubuntu.yml @@ -1,10 +1,8 @@ -defaults: - mode: healthcheck devices: /dev/vdb: fs: xfs label: lasith-rules - mountPoint: /ifmx/tempp + mountPoint: /ifmx/temp mountOptions: defaults group: ubuntu user: ubuntu diff --git a/internal/action/action.go b/internal/action/action.go index fb566c5..d8190b8 100644 --- a/internal/action/action.go +++ b/internal/action/action.go @@ -31,11 +31,7 @@ func NewActionExecutor(rc utils.RunnerFactory, c *config.Config) *ActionExecutor func (ae *ActionExecutor) ExecuteAction(action Action) error { name := action.GetDeviceName() - mode, err := ae.config.GetMode(name) - if err != nil { - return err - } - switch mode { + switch ae.config.GetMode(name) { case config.Prompt: if !ae.ShouldProceed(action) { return fmt.Errorf("🔴 Action rejected. %s", action.Refuse()) diff --git a/internal/config/config.go b/internal/config/config.go index 78272eb..5d4f1cd 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -70,10 +70,12 @@ type Overrides struct { ResizeFs bool `yaml:"resizeFs"` } +// We don't export "overrides" as this is an attribute that is used +// internally to store the state of flag overrides type Config struct { Defaults Defaults `yaml:"defaults"` - Overrides Overrides `yaml:"overrides"` Devices map[string]Device `yaml:"devices"` + overrides Overrides } func Parse(args []string) (*Config, *Flag, error) { @@ -128,21 +130,25 @@ func parseFlags(program string, args []string) (*Flag, error) { return flag, nil } -func (c *Config) GetMode(name string) (Mode, error) { +func (c *Config) GetMode(name string) Mode { cd, found := c.Devices[name] if !found { - return Empty, fmt.Errorf("🔴 %s: Could not find device in config", name) + return Healtcheck } - if c.Overrides.Mode != Empty { - return c.Overrides.Mode, nil + // Overrides handler + if c.overrides.Mode != Empty { + return c.overrides.Mode } + // Defaults handler if cd.Mode == Empty && c.Defaults.Mode != Empty { - return c.Defaults.Mode, nil + return c.Defaults.Mode } + // Device handler if cd.Mode != Empty { - return cd.Mode, nil + return cd.Mode } - return Empty, fmt.Errorf("🔴 %s: Ensure that you have provided a supported mode locally or globally", name) + // Fallback + return Healtcheck } func (c *Config) GetRemount(name string) bool { @@ -150,7 +156,7 @@ func (c *Config) GetRemount(name string) bool { if !found { return false } - return c.Overrides.Remount || c.Defaults.Remount || cd.Remount + return c.overrides.Remount || c.Defaults.Remount || cd.Remount } func (c *Config) GetResizeFs(name string) bool { @@ -158,5 +164,5 @@ func (c *Config) GetResizeFs(name string) bool { if !found { return false } - return c.Overrides.ResizeFs || c.Defaults.ResizeFs || cd.ResizeFs + return c.overrides.ResizeFs || c.Defaults.ResizeFs || cd.ResizeFs } diff --git a/internal/config/modifier.go b/internal/config/modifier.go index f003c32..b78f15e 100644 --- a/internal/config/modifier.go +++ b/internal/config/modifier.go @@ -46,9 +46,9 @@ func (om *OverridesModifier) Modify(c *Config) error { if err != nil { return err } - c.Overrides.Mode = mode - c.Overrides.Remount = om.flag.Remount - c.Overrides.ResizeFs = om.flag.ResizeFs + c.overrides.Mode = mode + c.overrides.Remount = om.flag.Remount + c.overrides.ResizeFs = om.flag.ResizeFs return nil } diff --git a/internal/config/validator.go b/internal/config/validator.go index e5b420a..02104b1 100644 --- a/internal/config/validator.go +++ b/internal/config/validator.go @@ -84,7 +84,7 @@ func (fsv *ModeValidator) Validate(c *Config) error { return fmt.Errorf("🔴 %s is not a supported global mode", mode) } - mode = string(c.Overrides.Mode) + mode = string(c.overrides.Mode) _, err = ParseMode(mode) if err != nil { return fmt.Errorf("🔴 %s is not a supported overrides mode", mode)