Skip to content

Commit

Permalink
rm alpha3, add alpha4
Browse files Browse the repository at this point in the history
  • Loading branch information
nxcc committed Sep 2, 2024
1 parent afdd1fc commit 5f0fff9
Show file tree
Hide file tree
Showing 22 changed files with 424 additions and 653 deletions.
14 changes: 11 additions & 3 deletions cmd/cuegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ package main
import (
"os"

v1alpha3 "github.com/noris-network/cuegen/internal/app/v1alpha3"
v1alpha1 "github.com/noris-network/cuegen/internal/app/v1alpha1"
v1alpha4 "github.com/noris-network/cuegen/internal/app/v1alpha4"
)

var build = "dev-build"

func main() {
v1alpha3.Build = build
os.Exit(v1alpha3.Main())
v1alpha1.Build = build
v1alpha4.Build = build

// shortcut to legacy version
if os.Getenv("CUEGEN_COMPATIBILITY_0_14") == "true" {
os.Exit(v1alpha1.Main())
}

os.Exit(v1alpha4.Main())
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/noris-network/cuegen

go 1.22
go 1.23

require (
cuelang.org/go v0.10.0
Expand Down
35 changes: 20 additions & 15 deletions internal/app/v1alpha3/main.go → internal/app/v1alpha4/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
_ "embed"
"flag"
"fmt"
"log"
"log/slog"
"os"
"runtime/debug"
"strings"

v1alpha1 "github.com/noris-network/cuegen/internal/app/v1alpha1"
cuegen "github.com/noris-network/cuegen/internal/cuegen/v1alpha3"
cuegen "github.com/noris-network/cuegen/internal/cuegen/v1alpha4"
"github.com/nxcc/cueconfig"
)

Expand All @@ -36,18 +36,24 @@ const (
//go:embed schema.cue
var configSchema []byte

var Build string
var debugLog = os.Getenv("CUEGEN_DEBUG") == "true"
var (
Build string
debugLog = os.Getenv("CUEGEN_DEBUG") == "true"
cuegenWrapper = os.Getenv("CUEGEN_SKIP_DECRYPT") != "true"
)

func Main() int {

flagIsCuegenDir := false

flag.BoolVar(&flagIsCuegenDir, "is-cuegen-dir", false,
"check current working directory for cuegen.{yaml,cue} (for cmp detection)")

flag.Parse()

if debugLog {
slog.SetLogLoggerLevel(slog.LevelDebug)
}

path := "."

switch {
Expand All @@ -62,11 +68,11 @@ func Main() int {
printVersion()
return 0

// no chdir
// path = .
case len(os.Args) == 1,
len(os.Args) == 2 && (os.Args[1] == "." || os.Args[1] == "./"):

// chdir
// path != .
case len(os.Args) == 2 && (strings.HasPrefix(os.Args[1], "./") || strings.HasPrefix(os.Args[1], "../") || strings.HasPrefix(os.Args[1], "/")):
path = os.Args[1]

Expand All @@ -81,13 +87,13 @@ func Main() int {
fmt.Printf("configure: %v\n", err)
return 1
}
if config.ApiVersion != cuegen.V1Alpha3 {
if config.ApiVersion == cuegen.V1Alpha1 {
fallbackToV1Alpha1()
}

// exec
// exec V1Alpha4
if err := cuegen.Exec(config, path); err != nil {
fmt.Printf("exec: %v\n", err)
fmt.Printf("%v\n", err)
return 1
}

Expand All @@ -107,7 +113,8 @@ func printVersion() {
fmt.Printf("cuegen version %v\n", Build)
bi, ok := debug.ReadBuildInfo()
if !ok {
log.Fatalln("Failed to read build info")
slog.Error("failed to read build info")
os.Exit(1)
}
for _, dep := range bi.Deps {
if dep.Path == "cuelang.org/go" {
Expand All @@ -120,17 +127,15 @@ func printVersion() {
func configure() (cuegen.Cuegen, error) {
cfg := struct{ Cuegen cuegen.Cuegen }{}
if err := cueconfig.Load(cuegenCue, configSchema, nil, nil, &cfg); err != nil {
if os.IsNotExist(err) {
return cuegen.Default, nil
}
slog.Error("load cuegen.cue", "err", err)
return cuegen.Cuegen{}, err
}
return cfg.Cuegen, nil
}

func fallbackToV1Alpha1() {
if debugLog {
fmt.Println("#@@@ fallback to v1alpha1")
slog.Debug("fallback to v1alpha1")
}
os.Exit(v1alpha1.Main())
}
File renamed without changes.
77 changes: 0 additions & 77 deletions internal/cuegen/v1alpha3/dev-registry.go

This file was deleted.

Loading

0 comments on commit 5f0fff9

Please sign in to comment.