az-pim-cli: fix version command, don't use emulator for shell completions (#414070)

This commit is contained in:
Paul Meyer 2025-06-08 21:54:55 +02:00 committed by GitHub
commit b3231088cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 15 deletions

View file

@ -4,10 +4,8 @@
fetchFromGitHub, fetchFromGitHub,
installShellFiles, installShellFiles,
stdenv, stdenv,
buildPackages,
nix-update-script, nix-update-script,
testers, testers,
az-pim-cli,
}: }:
buildGoModule (finalAttrs: { buildGoModule (finalAttrs: {
pname = "az-pim-cli"; pname = "az-pim-cli";
@ -20,29 +18,37 @@ buildGoModule (finalAttrs: {
hash = "sha256-gf4VscHaUr3JtsJO5PAq1nyPeJxIwGPaiH/QdXKpvQ0="; hash = "sha256-gf4VscHaUr3JtsJO5PAq1nyPeJxIwGPaiH/QdXKpvQ0=";
}; };
patches = [
# removes info we don't have from version command
./version-build-info.patch
];
vendorHash = "sha256-PHrpUlAG/PBe3NKUGBQ1U7dCcqkSlErWX2dp9ZPB3+8="; vendorHash = "sha256-PHrpUlAG/PBe3NKUGBQ1U7dCcqkSlErWX2dp9ZPB3+8=";
nativeBuildInputs = [ nativeBuildInputs = [
installShellFiles installShellFiles
]; ];
postInstall = lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) ( env.CGO_ENABLED = 0;
let
emulator = stdenv.hostPlatform.emulator buildPackages; ldflags = [
in "-s"
'' "-X github.com/netr0m/az-pim-cli/cmd.version=v${finalAttrs.version}"
];
postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installShellCompletion --cmd az-pim-cli \ installShellCompletion --cmd az-pim-cli \
--bash <(${emulator} $out/bin/az-pim-cli completion bash) \ --bash <($out/bin/az-pim-cli completion bash) \
--fish <(${emulator} $out/bin/az-pim-cli completion fish) \ --fish <($out/bin/az-pim-cli completion fish) \
--zsh <(${emulator} $out/bin/az-pim-cli completion zsh) --zsh <($out/bin/az-pim-cli completion zsh)
'' '';
);
passthru = { passthru = {
updateScript = nix-update-script { }; updateScript = nix-update-script { };
tests.version = testers.testVersion { tests.version = testers.testVersion {
command = "HOME=$TMPDIR az-pim-cli --version"; command = "HOME=$TMPDIR az-pim-cli version";
package = az-pim-cli; package = finalAttrs.finalPackage;
version = "v${finalAttrs.version}";
}; };
}; };

View file

@ -0,0 +1,24 @@
diff --git a/cmd/version.go b/cmd/version.go
index 816f044..ef107be 100644
--- a/cmd/version.go
+++ b/cmd/version.go
@@ -31,8 +31,7 @@ type BuildInfo struct {
}
func (b BuildInfo) String() string {
- return fmt.Sprintf("az-pim-cli version %s (built with %s from %s on %s)",
- b.Version, b.GoVersion, b.Commit, b.Date)
+ return fmt.Sprintf("az-pim-cli version %s", b.Version)
}
func printVersion(w io.Writer, info BuildInfo) {
@@ -47,8 +46,8 @@ func createBuildInfo() BuildInfo {
Date: date,
}
- buildInfo, available := debug.ReadBuildInfo()
- if !available {
+ buildInfo, _ := debug.ReadBuildInfo()
+ if true {
return info
}