vlp/internal/commands/build/command.go

46 lines
761 B
Go
Raw Normal View History

2024-09-19 02:12:57 +02:00
package build
import (
"fmt"
"code.vulpine.solutions/sam/vlp/internal/packages"
"code.vulpine.solutions/sam/vlp/internal/state"
"github.com/urfave/cli/v2"
)
var Command = &cli.Command{
Name: "build",
Aliases: []string{"b"},
Usage: "Build a package from source",
Args: true,
ArgsUsage: "<name>",
Action: action,
}
func action(ctx *cli.Context) error {
if ctx.NArg() < 1 {
return cli.Exit("Not enough arguments", 1)
}
name := ctx.Args().Get(0)
script, err := packages.LookupPackageFile(name)
if err != nil {
return err
}
s := state.New(name)
err = s.Eval(script)
if err != nil {
return err
}
err = s.Build()
if err != nil {
return err
}
fmt.Println(s.Builder.Name, s.Builder.Dependencies)
return nil
}