license: embed license in executable

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
Ophestra 2024-07-16 22:07:40 +09:00
parent 09507a541b
commit 7e6eb82195
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
4 changed files with 37 additions and 6 deletions

7
cli.go
View File

@ -25,10 +25,9 @@ func init() {
} }
func copyArgs() { func copyArgs() {
if printVersion { tryLauncher()
fmt.Println(Version) tryVersion()
os.Exit(0) tryLicense()
}
command = flag.Args() command = flag.Args()

View File

@ -31,7 +31,7 @@
packages = [ packages = [
(buildGoModule rec { (buildGoModule rec {
pname = "ego"; pname = "ego";
version = "flake"; version = "0.0.0-flake";
src = ./.; src = ./.;
vendorHash = null; # we have no dependencies :3 vendorHash = null; # we have no dependencies :3

26
license.go Normal file
View File

@ -0,0 +1,26 @@
package main
import (
_ "embed"
"flag"
"fmt"
"os"
)
var (
//go:embed LICENSE
license string
printLicense bool
)
func init() {
flag.BoolVar(&printLicense, "license", false, "Print license")
}
func tryLicense() {
if printLicense {
fmt.Println(license)
os.Exit(0)
}
}

View File

@ -16,6 +16,13 @@ import (
var Version = "impure" var Version = "impure"
func tryVersion() {
if printVersion {
fmt.Println(Version)
os.Exit(0)
}
}
var ( var (
ego *user.User ego *user.User
uid int uid int
@ -42,7 +49,6 @@ const (
func main() { func main() {
flag.Parse() flag.Parse()
tryLauncher()
copyArgs() copyArgs()
if u, err := strconv.Atoi(ego.Uid); err != nil { if u, err := strconv.Atoi(ego.Uid); err != nil {