// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

// Package main is the entry point for the lune CLI.
package main

import (
	"context"
	"os"
	"runtime/debug"

	"git.secluded.site/lune/cmd"
)

// version is set at build time via ldflags for release builds.
// For go install, we read from debug.ReadBuildInfo() instead.
var version = "dev"

func main() {
	if err := cmd.Execute(context.Background(), resolveVersion()); err != nil {
		os.Exit(1)
	}
}

// resolveVersion returns the ldflags-injected version if set (release builds,
// task install), otherwise falls back to build info (go install from proxy).
func resolveVersion() string {
	if version != "dev" {
		return version
	}

	info, ok := debug.ReadBuildInfo()
	if ok && info.Main.Version != "" && info.Main.Version != "(devel)" {
		return info.Main.Version
	}

	return version
}
