Move to yaml-based configuration
This commit updates the configuration to be yaml-based and updates the configuration to read in a yaml file.
This commit is contained in:
parent
568c005d15
commit
945329a080
70 changed files with 1150 additions and 350 deletions
64
cmd/config_migrate.go
Normal file
64
cmd/config_migrate.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/config"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/config/legacy"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
)
|
||||
|
||||
// ConfigMigrate is the config-migrate command
|
||||
var ConfigMigrate wisski_distillery.Command = cfgMigrate{}
|
||||
|
||||
type cfgMigrate struct {
|
||||
Positionals struct {
|
||||
Input string `positional-arg-name:"input" required:"1-1" description:"old config to migrate"`
|
||||
} `positional-args:"true"`
|
||||
}
|
||||
|
||||
func (cfgMigrate) Description() wisski_distillery.Description {
|
||||
return wisski_distillery.Description{
|
||||
Requirements: cli.Requirements{
|
||||
NeedsDistillery: false,
|
||||
},
|
||||
Command: "config_migrate",
|
||||
Description: "migrate legacy configuration",
|
||||
}
|
||||
}
|
||||
|
||||
func (c cfgMigrate) Run(context wisski_distillery.Context) error {
|
||||
// migration environment is the native environment!
|
||||
env := new(environment.Native)
|
||||
|
||||
// open the legacy file
|
||||
file, err := env.Open(c.Positionals.Input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// migrate from a legacy configuration
|
||||
// then marshal, and re-read
|
||||
|
||||
var cfg config.Config
|
||||
{
|
||||
var mconfig config.Config
|
||||
var output bytes.Buffer
|
||||
|
||||
if err := legacy.Migrate(&mconfig, env, file); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := mconfig.Marshal(&output); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cfg.Unmarshal(env, &output); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// do a final marshal
|
||||
return cfg.Marshal(context.Stdout)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue