Skip to content

Commit

Permalink
Merge pull request #204 from rsteube/parsing-string
Browse files Browse the repository at this point in the history
parsing: use string
  • Loading branch information
rsteube authored Aug 31, 2023
2 parents a0f8a93 + 551e204 commit fe1a796
Showing 1 changed file with 5 additions and 42 deletions.
47 changes: 5 additions & 42 deletions pkg/command/parsing.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,10 @@
package command

import (
"errors"

"gopkg.in/yaml.v3"
)

type Parsing int
type Parsing string

const (
DEFAULT Parsing = iota // INTERSPERSED but allows implicit changes
INTERSPERSED // mixed flags and positional arguments
NON_INTERSPERSED // flag parsing stopped after first positional argument
DISABLED // flag parsing disabled
DEFAULT Parsing = "" // INTERSPERSED but allows implicit changes
INTERSPERSED Parsing = "interspersed" // mixed flags and positional arguments
NON_INTERSPERSED Parsing = "non-interspersed" // flag parsing stopped after first positional argument
DISABLED Parsing = "disabled" // flag parsing disabled
)

func (p Parsing) MarshalYAML() (interface{}, error) {
switch p {
case DEFAULT:
return "", nil
case INTERSPERSED:
return "interspersed", nil
case NON_INTERSPERSED:
return "non-interspersed", nil
case DISABLED:
return "disabled", nil
default:
return "", errors.New("unknown parsing mode")
}
}

func (p *Parsing) UnmarshalYAML(value *yaml.Node) error {
switch value.Value {
case "":
*p = DEFAULT
case "interspersed":
*p = INTERSPERSED
case "non-interspersed":
*p = NON_INTERSPERSED
case "disabled":
*p = DISABLED
default:
return errors.New("unknown parsing mode")
}
return nil
}

0 comments on commit fe1a796

Please sign in to comment.