sbom-utility: Fix version, add shell completions (#395745)

authored by Aleksana and committed by GitHub 9fd498b7 ee299ea6

+119 -2
+13
pkgs/by-name/sb/sbom-utility/name.patch
··· 1 + diff --git a/cmd/root.go b/cmd/root.go 2 + index 5ef5d46..e99b245 100644 3 + --- a/cmd/root.go 4 + +++ b/cmd/root.go 5 + @@ -139,7 +139,7 @@ const ( 6 + ) 7 + 8 + var rootCmd = &cobra.Command{ 9 + - Use: fmt.Sprintf("%s [command] [flags]", utils.GlobalFlags.Project), 10 + + Use: fmt.Sprintf("sbom-utility [command] [flags]"), 11 + SilenceErrors: false, 12 + SilenceUsage: false, 13 + Short: MSG_APP_NAME,
+39 -2
pkgs/by-name/sb/sbom-utility/package.nix
··· 2 2 lib, 3 3 buildGoModule, 4 4 fetchFromGitHub, 5 + fetchpatch, 6 + versionCheckHook, 7 + installShellFiles, 8 + stdenv, 5 9 }: 6 10 7 - buildGoModule rec { 11 + let 12 + version = "0.17.0"; 13 + in 14 + buildGoModule { 8 15 pname = "sbom-utility"; 9 - version = "0.17.0"; 16 + inherit version; 10 17 11 18 src = fetchFromGitHub { 12 19 owner = "CycloneDX"; ··· 17 24 18 25 vendorHash = "sha256-vyYSir5u6d5nv+2ScrHpasQGER4VFSoLb1FDUDIrtDM="; 19 26 27 + patches = [ 28 + # work around https://github.com/CycloneDX/sbom-utility/issues/121, which otherwise 29 + # breaks shell completions 30 + ./name.patch 31 + # Output logs to stderr rather than stdout. 32 + # Patch of https://github.com/CycloneDX/sbom-utility/pull/122, adapted to apply 33 + # against v0.17.0 34 + ./stderr.patch 35 + ]; 36 + 37 + ldflags = [ 38 + "-X main.Version=${version}" 39 + ]; 40 + 41 + nativeBuildInputs = [ 42 + installShellFiles 43 + ]; 44 + 45 + nativeInstallCheckInputs = [ 46 + versionCheckHook 47 + ]; 48 + doInstallCheck = true; 49 + 20 50 preCheck = '' 21 51 cd test 52 + ''; 53 + 54 + postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' 55 + for shell in bash fish zsh; do 56 + installShellCompletion --cmd sbom-utility \ 57 + --$shell <($out/bin/sbom-utility -q completion $shell) 58 + done 22 59 ''; 23 60 24 61 meta = with lib; {
+67
pkgs/by-name/sb/sbom-utility/stderr.patch
··· 1 + diff --git a/log/log.go b/log/log.go 2 + index 2615f0a..c82b6c5 100644 3 + --- a/log/log.go 4 + +++ b/log/log.go 5 + @@ -104,7 +104,7 @@ func NewDefaultLogger() *MiniLogger { 6 + tagEnter: DEFAULT_ENTER_TAG, 7 + tagExit: DEFAULT_EXIT_TAG, 8 + tagColor: color.New(color.FgMagenta), 9 + - outputFile: os.Stdout, 10 + + outputFile: os.Stderr, 11 + maxStrLength: 64, 12 + } 13 + 14 + @@ -361,7 +361,7 @@ func (log MiniLogger) dumpInterface(lvl Level, tag string, value interface{}, sk 15 + } 16 + 17 + // TODO: use a general output writer (set to stdout, stderr, or file stream) 18 + - fmt.Println(sb.String()) 19 + + fmt.Fprintln(log.outputFile, sb.String()) 20 + } else { 21 + os.Stderr.WriteString("Error: Unable to retrieve call stack. Exiting...") 22 + os.Exit(-2) 23 + @@ -370,7 +370,7 @@ func (log MiniLogger) dumpInterface(lvl Level, tag string, value interface{}, sk 24 + } 25 + 26 + func (log MiniLogger) DumpString(value string) { 27 + - fmt.Print(value) 28 + + fmt.Fprint(log.outputFile, value) 29 + } 30 + 31 + func (log MiniLogger) DumpStruct(structName string, field interface{}) error { 32 + @@ -389,7 +389,7 @@ func (log MiniLogger) DumpStruct(structName string, field interface{}) error { 33 + } 34 + 35 + // TODO: print to output stream 36 + - fmt.Println(sb.String()) 37 + + fmt.Fprintln(log.outputFile, sb.String()) 38 + 39 + return nil 40 + } 41 + @@ -398,8 +398,8 @@ func (log MiniLogger) DumpArgs() { 42 + args := os.Args 43 + for i, a := range args { 44 + // TODO: print to output stream 45 + - fmt.Print(log.indentRunes) 46 + - fmt.Printf("os.Arg[%d]: `%v`\n", i, a) 47 + + fmt.Fprint(log.outputFile, log.indentRunes) 48 + + fmt.Fprintf(log.outputFile, "os.Arg[%d]: `%v`\n", i, a) 49 + } 50 + } 51 + 52 + @@ -409,7 +409,7 @@ func (log MiniLogger) DumpSeparator(sep byte, repeat int) (string, error) { 53 + for i := 0; i < repeat; i++ { 54 + sb.WriteByte(sep) 55 + } 56 + - fmt.Println(sb.String()) 57 + + fmt.Fprintln(log.outputFile, sb.String()) 58 + return sb.String(), nil 59 + } else { 60 + return "", errors.New("invalid repeat length (>80)") 61 + @@ -417,5 +417,5 @@ func (log MiniLogger) DumpSeparator(sep byte, repeat int) (string, error) { 62 + } 63 + 64 + func (log *MiniLogger) DumpStackTrace() { 65 + - fmt.Println(string(debug.Stack())) 66 + + fmt.Fprintln(log.outputFile, string(debug.Stack())) 67 + }