mirror of
https://github.com/mudler/luet.git
synced 2025-09-25 14:38:50 +00:00
Add json output to build
This commit is contained in:
63
cmd/build.go
63
cmd/build.go
@@ -15,9 +15,11 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/ghodss/yaml"
|
||||||
helpers "github.com/mudler/luet/cmd/helpers"
|
helpers "github.com/mudler/luet/cmd/helpers"
|
||||||
"github.com/mudler/luet/pkg/compiler"
|
"github.com/mudler/luet/pkg/compiler"
|
||||||
"github.com/mudler/luet/pkg/compiler/backend"
|
"github.com/mudler/luet/pkg/compiler/backend"
|
||||||
@@ -83,7 +85,13 @@ var buildCmd = &cobra.Command{
|
|||||||
full, _ := cmd.Flags().GetBool("full")
|
full, _ := cmd.Flags().GetBool("full")
|
||||||
skip, _ := cmd.Flags().GetBool("skip-if-metadata-exists")
|
skip, _ := cmd.Flags().GetBool("skip-if-metadata-exists")
|
||||||
concurrent, _ := cmd.Flags().GetBool("solver-concurrent")
|
concurrent, _ := cmd.Flags().GetBool("solver-concurrent")
|
||||||
|
var results Results
|
||||||
|
|
||||||
|
out, _ := cmd.Flags().GetString("output")
|
||||||
|
if out != "terminal" {
|
||||||
|
LuetCfg.GetLogging().SetLogLevel("error")
|
||||||
|
}
|
||||||
|
pretend, _ := cmd.Flags().GetBool("pretend")
|
||||||
compilerSpecs := compiler.NewLuetCompilationspecs()
|
compilerSpecs := compiler.NewLuetCompilationspecs()
|
||||||
var compilerBackend compiler.CompilerBackend
|
var compilerBackend compiler.CompilerBackend
|
||||||
var db pkg.PackageDatabase
|
var db pkg.PackageDatabase
|
||||||
@@ -205,9 +213,58 @@ var buildCmd = &cobra.Command{
|
|||||||
if revdeps {
|
if revdeps {
|
||||||
artifact, errs = luetCompiler.CompileWithReverseDeps(privileged, compilerSpecs)
|
artifact, errs = luetCompiler.CompileWithReverseDeps(privileged, compilerSpecs)
|
||||||
|
|
||||||
|
} else if pretend {
|
||||||
|
toCalculate := []compiler.CompilationSpec{}
|
||||||
|
if full {
|
||||||
|
var err error
|
||||||
|
toCalculate, err = luetCompiler.ComputeMinimumCompilableSet(compilerSpecs.All()...)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toCalculate = compilerSpecs.All()
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, sp := range toCalculate {
|
||||||
|
packs, err := luetCompiler.ComputeDepTree(sp)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
for _, p := range packs {
|
||||||
|
results.Packages = append(results.Packages,
|
||||||
|
PackageResult{
|
||||||
|
Name: p.Package.GetName(),
|
||||||
|
Version: p.Package.GetVersion(),
|
||||||
|
Category: p.Package.GetCategory(),
|
||||||
|
Repository: "",
|
||||||
|
Hidden: p.Package.IsHidden(),
|
||||||
|
Target: sp.GetPackage().HumanReadableString(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
y, err := yaml.Marshal(results)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("err: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch out {
|
||||||
|
case "yaml":
|
||||||
|
fmt.Println(string(y))
|
||||||
|
case "json":
|
||||||
|
j2, err := yaml.YAMLToJSON(y)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("err: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(string(j2))
|
||||||
|
case "terminal":
|
||||||
|
for _, p := range results.Packages {
|
||||||
|
Info(p.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
artifact, errs = luetCompiler.CompileParallel(privileged, compilerSpecs)
|
artifact, errs = luetCompiler.CompileParallel(privileged, compilerSpecs)
|
||||||
|
|
||||||
}
|
}
|
||||||
if len(errs) != 0 {
|
if len(errs) != 0 {
|
||||||
for _, e := range errs {
|
for _, e := range errs {
|
||||||
@@ -252,5 +309,9 @@ func init() {
|
|||||||
buildCmd.Flags().Int("solver-attempts", 9000, "Solver maximum attempts")
|
buildCmd.Flags().Int("solver-attempts", 9000, "Solver maximum attempts")
|
||||||
buildCmd.Flags().Bool("solver-concurrent", false, "Use concurrent solver (experimental)")
|
buildCmd.Flags().Bool("solver-concurrent", false, "Use concurrent solver (experimental)")
|
||||||
|
|
||||||
|
buildCmd.Flags().Bool("pretend", false, "Just print what packages will be compiled")
|
||||||
|
|
||||||
|
buildCmd.Flags().StringP("output", "o", "terminal", "Output format ( Defaults: terminal, available: json,yaml )")
|
||||||
|
|
||||||
RootCmd.AddCommand(buildCmd)
|
RootCmd.AddCommand(buildCmd)
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,7 @@ type PackageResult struct {
|
|||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Repository string `json:"repository"`
|
Repository string `json:"repository"`
|
||||||
|
Target string `json:"target"`
|
||||||
Hidden bool `json:"hidden"`
|
Hidden bool `json:"hidden"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +40,10 @@ type Results struct {
|
|||||||
Packages []PackageResult `json:"packages"`
|
Packages []PackageResult `json:"packages"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r PackageResult) String() string {
|
||||||
|
return fmt.Sprintf("%s/%s-%s required for %s", r.Category, r.Name, r.Version, r.Target)
|
||||||
|
}
|
||||||
|
|
||||||
var searchCmd = &cobra.Command{
|
var searchCmd = &cobra.Command{
|
||||||
Use: "search <term>",
|
Use: "search <term>",
|
||||||
Short: "Search packages",
|
Short: "Search packages",
|
||||||
|
Reference in New Issue
Block a user