Skip to content

Commit

Permalink
(feat): Improve parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lasith-kg committed Dec 25, 2023
1 parent 5cd57b2 commit 9baddab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion internal/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (dae *DefaultActionExecutor) execute(action Action) error {
if !dae.shouldProceed(action) {
return fmt.Errorf("🔴 Action rejected. %s", action.Refuse())
}
case config.Healtcheck:
case config.Healthcheck:
return fmt.Errorf("🔴 Healthcheck mode enabled. %s", action.Refuse())
default:
return fmt.Errorf("🔴 Unexpected mode detected. %s", action.Refuse())
Expand Down
29 changes: 12 additions & 17 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,20 @@ const (
type Mode string

const (
Empty Mode = ""
Healtcheck Mode = "healthcheck"
Prompt Mode = "prompt"
Force Mode = "force"
Empty Mode = ""
Healthcheck Mode = "healthcheck"
Prompt Mode = "prompt"
Force Mode = "force"
)

func ParseMode(s string) (Mode, error) {
Modes := map[Mode]struct{}{
Empty: {},
Healtcheck: {},
Prompt: {},
Force: {},
m := Mode(s)
switch m {
case Empty, Healthcheck, Prompt, Force:
return m, nil
default:
return m, fmt.Errorf("🔴 %s: Mode is not supported", s)
}
fst := Mode(s)
_, ok := Modes[fst]
if !ok {
return fst, fmt.Errorf("🔴 %s: Mode is not supported", s)
}
return fst, nil
}

type Flag struct {
Expand Down Expand Up @@ -151,7 +146,7 @@ func (c *Config) setOverrides(f *Flag) *Config {
func (c *Config) GetMode(name string) Mode {
cd, found := c.Devices[name]
if !found {
return Healtcheck
return Healthcheck
}
if c.overrides.Mode != Empty {
return c.overrides.Mode
Expand All @@ -162,7 +157,7 @@ func (c *Config) GetMode(name string) Mode {
if c.Defaults.Mode != Empty {
return c.Defaults.Mode
}
return Healtcheck
return Healthcheck
}

func (c *Config) GetRemount(name string) bool {
Expand Down
12 changes: 4 additions & 8 deletions internal/model/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ const (
)

func ParseFileSystem(s string) (FileSystem, error) {
FileSystems := map[FileSystem]struct{}{
Unformatted: {},
Ext4: {},
Xfs: {},
}
fst := FileSystem(s)
_, ok := FileSystems[fst]
if !ok {
switch fst {
case Unformatted, Ext4, Xfs:
return fst, nil
default:
return fst, fmt.Errorf("🔴 %s: File system is not supported", s)
}
return fst, nil
}

0 comments on commit 9baddab

Please sign in to comment.