From 7e6eb82195c650bc34829e5cca2d2296e78c0707 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Tue, 16 Jul 2024 22:07:40 +0900 Subject: [PATCH] license: embed license in executable Signed-off-by: Ophestra Umiker --- cli.go | 7 +++---- flake.nix | 2 +- license.go | 26 ++++++++++++++++++++++++++ main.go | 8 +++++++- 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 license.go diff --git a/cli.go b/cli.go index 9a4d3a0..ca1b41b 100644 --- a/cli.go +++ b/cli.go @@ -25,10 +25,9 @@ func init() { } func copyArgs() { - if printVersion { - fmt.Println(Version) - os.Exit(0) - } + tryLauncher() + tryVersion() + tryLicense() command = flag.Args() diff --git a/flake.nix b/flake.nix index 48cb435..8c8e419 100644 --- a/flake.nix +++ b/flake.nix @@ -31,7 +31,7 @@ packages = [ (buildGoModule rec { pname = "ego"; - version = "flake"; + version = "0.0.0-flake"; src = ./.; vendorHash = null; # we have no dependencies :3 diff --git a/license.go b/license.go new file mode 100644 index 0000000..4cbe012 --- /dev/null +++ b/license.go @@ -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) + } +} diff --git a/main.go b/main.go index ed5566e..4a719d8 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,13 @@ import ( var Version = "impure" +func tryVersion() { + if printVersion { + fmt.Println(Version) + os.Exit(0) + } +} + var ( ego *user.User uid int @@ -42,7 +49,6 @@ const ( func main() { flag.Parse() - tryLauncher() copyArgs() if u, err := strconv.Atoi(ego.Uid); err != nil {