-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from rsteube/parsing-string
parsing: use string
- Loading branch information
Showing
1 changed file
with
5 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |