generated from snivilised/arcadia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nav): move config readers into command pkg (#92)
- Loading branch information
1 parent
6f67c65
commit 906001a
Showing
4 changed files
with
64 additions
and
55 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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/snivilised/cobrass/src/assistant/configuration" | ||
"github.com/snivilised/cobrass/src/clif" | ||
"github.com/snivilised/pixa/src/app/proxy" | ||
) | ||
|
||
type MsProfilesConfigReader struct { | ||
} | ||
|
||
func (r *MsProfilesConfigReader) Read(viper configuration.ViperConfig) (proxy.ProfilesConfig, error) { | ||
// Ideally, the ProfileParameterSet would perform a check against | ||
// the config, but extendio is not aware of config, so it can't | ||
// check. Instead, we can check here. | ||
// | ||
profilesCFG := &proxy.MsProfilesConfig{ | ||
Profiles: make(proxy.ProfilesConfigMap), | ||
} | ||
|
||
if raw := viper.Get("profiles"); raw != nil { | ||
if profiles, ok := raw.(proxy.ProfilesFlagOptionAsAnyPair); ok { | ||
for profile, pv := range profiles { | ||
if pair, ok := pv.(proxy.ProfilesFlagOptionAsAnyPair); ok { | ||
profilesCFG.Profiles[profile] = make(clif.ChangedFlagsMap) | ||
|
||
for flag, optionAsAny := range pair { | ||
profilesCFG.Profiles[profile][flag] = fmt.Sprint(optionAsAny) | ||
} | ||
} | ||
} | ||
} else { | ||
return nil, fmt.Errorf("invalid type for 'profiles'") | ||
} | ||
} | ||
|
||
return profilesCFG, nil | ||
} | ||
|
||
type MsSamplerConfigReader struct{} | ||
|
||
func (r *MsSamplerConfigReader) Read(viper configuration.ViperConfig) (proxy.SamplerConfig, error) { | ||
var ( | ||
samplerCFG proxy.MsSamplerConfig | ||
) | ||
|
||
err := viper.UnmarshalKey("sampler", &samplerCFG) | ||
|
||
return &samplerCFG, err | ||
} | ||
|
||
type ConfigReaders struct { | ||
Profiles proxy.ProfilesConfigReader | ||
Sampler proxy.SamplerConfigReader | ||
} |
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
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