✨ Add mkflex command
This commit is contained in:
parent
72295c53cf
commit
f4497aef7e
7 changed files with 333 additions and 1 deletions
53
internal/cli/mkflex/app.go
Normal file
53
internal/cli/mkflex/app.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package mkflex
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
conutils "codeberg.org/danjones000/utils/convids"
|
||||
mkutils "codeberg.org/danjones000/utils/mkflex"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func NewApp(ctx context.Context, name string, args []string, dataPath, templatePath, outPath string) (*App, error) {
|
||||
var err error
|
||||
a := App{
|
||||
Name: name,
|
||||
Path: outPath,
|
||||
}
|
||||
|
||||
a.Data, err = conutils.NewData(dataPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a.Config, err = mkutils.NewConfig(templatePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &a, nil
|
||||
}
|
||||
|
||||
type App struct {
|
||||
Name string
|
||||
Data *conutils.Data
|
||||
Path string
|
||||
Config *mkutils.Config
|
||||
}
|
||||
|
||||
func (a *App) Run(ctx context.Context) error {
|
||||
out, err := os.Create(a.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
enc := yaml.NewEncoder(out)
|
||||
enc.SetIndent(2)
|
||||
|
||||
if err := mkutils.AddShows(a.Config, a.Data); err != nil {
|
||||
return err
|
||||
}
|
||||
delete(a.Config.Templates, "x-aliases")
|
||||
|
||||
return enc.Encode(a.Config)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue