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

This commit is contained in:
Aleksana
2025-04-10 17:09:39 +08:00
committed by GitHub
3 changed files with 119 additions and 2 deletions
+13
View File
@@ -0,0 +1,13 @@
diff --git a/cmd/root.go b/cmd/root.go
index 5ef5d46..e99b245 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -139,7 +139,7 @@ const (
)
var rootCmd = &cobra.Command{
- Use: fmt.Sprintf("%s [command] [flags]", utils.GlobalFlags.Project),
+ Use: fmt.Sprintf("sbom-utility [command] [flags]"),
SilenceErrors: false,
SilenceUsage: false,
Short: MSG_APP_NAME,
+39 -2
View File
@@ -2,11 +2,18 @@
lib,
buildGoModule,
fetchFromGitHub,
fetchpatch,
versionCheckHook,
installShellFiles,
stdenv,
}:
buildGoModule rec {
pname = "sbom-utility";
let
version = "0.17.0";
in
buildGoModule {
pname = "sbom-utility";
inherit version;
src = fetchFromGitHub {
owner = "CycloneDX";
@@ -17,10 +24,40 @@ buildGoModule rec {
vendorHash = "sha256-vyYSir5u6d5nv+2ScrHpasQGER4VFSoLb1FDUDIrtDM=";
patches = [
# work around https://github.com/CycloneDX/sbom-utility/issues/121, which otherwise
# breaks shell completions
./name.patch
# Output logs to stderr rather than stdout.
# Patch of https://github.com/CycloneDX/sbom-utility/pull/122, adapted to apply
# against v0.17.0
./stderr.patch
];
ldflags = [
"-X main.Version=${version}"
];
nativeBuildInputs = [
installShellFiles
];
nativeInstallCheckInputs = [
versionCheckHook
];
doInstallCheck = true;
preCheck = ''
cd test
'';
postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
for shell in bash fish zsh; do
installShellCompletion --cmd sbom-utility \
--$shell <($out/bin/sbom-utility -q completion $shell)
done
'';
meta = with lib; {
description = "Utility that provides an API platform for validating, querying and managing BOM data";
homepage = "https://github.com/CycloneDX/sbom-utility";
+67
View File
@@ -0,0 +1,67 @@
diff --git a/log/log.go b/log/log.go
index 2615f0a..c82b6c5 100644
--- a/log/log.go
+++ b/log/log.go
@@ -104,7 +104,7 @@ func NewDefaultLogger() *MiniLogger {
tagEnter: DEFAULT_ENTER_TAG,
tagExit: DEFAULT_EXIT_TAG,
tagColor: color.New(color.FgMagenta),
- outputFile: os.Stdout,
+ outputFile: os.Stderr,
maxStrLength: 64,
}
@@ -361,7 +361,7 @@ func (log MiniLogger) dumpInterface(lvl Level, tag string, value interface{}, sk
}
// TODO: use a general output writer (set to stdout, stderr, or file stream)
- fmt.Println(sb.String())
+ fmt.Fprintln(log.outputFile, sb.String())
} else {
os.Stderr.WriteString("Error: Unable to retrieve call stack. Exiting...")
os.Exit(-2)
@@ -370,7 +370,7 @@ func (log MiniLogger) dumpInterface(lvl Level, tag string, value interface{}, sk
}
func (log MiniLogger) DumpString(value string) {
- fmt.Print(value)
+ fmt.Fprint(log.outputFile, value)
}
func (log MiniLogger) DumpStruct(structName string, field interface{}) error {
@@ -389,7 +389,7 @@ func (log MiniLogger) DumpStruct(structName string, field interface{}) error {
}
// TODO: print to output stream
- fmt.Println(sb.String())
+ fmt.Fprintln(log.outputFile, sb.String())
return nil
}
@@ -398,8 +398,8 @@ func (log MiniLogger) DumpArgs() {
args := os.Args
for i, a := range args {
// TODO: print to output stream
- fmt.Print(log.indentRunes)
- fmt.Printf("os.Arg[%d]: `%v`\n", i, a)
+ fmt.Fprint(log.outputFile, log.indentRunes)
+ fmt.Fprintf(log.outputFile, "os.Arg[%d]: `%v`\n", i, a)
}
}
@@ -409,7 +409,7 @@ func (log MiniLogger) DumpSeparator(sep byte, repeat int) (string, error) {
for i := 0; i < repeat; i++ {
sb.WriteByte(sep)
}
- fmt.Println(sb.String())
+ fmt.Fprintln(log.outputFile, sb.String())
return sb.String(), nil
} else {
return "", errors.New("invalid repeat length (>80)")
@@ -417,5 +417,5 @@ func (log MiniLogger) DumpSeparator(sep byte, repeat int) (string, error) {
}
func (log *MiniLogger) DumpStackTrace() {
- fmt.Println(string(debug.Stack()))
+ fmt.Fprintln(log.outputFile, string(debug.Stack()))
}