Skip to content

Commit

Permalink
[cpackget] Debug log level not working on some commands #131
Browse files Browse the repository at this point in the history
fixed:
- initializing verbose option
- fixed crash in sanitizeVersionForSignature() accessing [0] of empty string
  • Loading branch information
thorstendb-ARM committed Jun 14, 2023
1 parent dc6443b commit 1a7f3c5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/commands/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ might be supported. The used function will be prefixed to the ".checksum" extens
By default the checksum file will be created in the same directory as the provided pack.`,
Args: cobra.ExactArgs(1),
PersistentPreRunE: configureInstaller,
PersistentPreRunE: configureInstallerVerbose,
RunE: func(cmd *cobra.Command, args []string) error {
return cryptography.GenerateChecksum(args[0], checksumCreateCmdFlags.outputDir, checksumCreateCmdFlags.hashAlgorithm)
},
Expand All @@ -75,7 +75,7 @@ The used hash function is inferred from the checksum filename, and if any of the
computed doesn't match the one provided in the checksum file an error will be thrown.
If the .checksum file is in another directory, specify it with the -p/--path flag`,
Args: cobra.ExactArgs(1),
PersistentPreRunE: configureInstaller,
PersistentPreRunE: configureInstallerVerbose,
RunE: func(cmd *cobra.Command, args []string) error {
if checksumVerifyCmdFlags.checksumPath != "" {
return cryptography.VerifyChecksum(args[0], checksumVerifyCmdFlags.checksumPath)
Expand Down
13 changes: 11 additions & 2 deletions cmd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ const defaultPublicIndex = "https://www.keil.com/pack/index.pidx"

var viper *viperType.Viper

// configureInstaller configures cpackget installer for adding or removing pack/pdsc
func configureInstaller(cmd *cobra.Command, args []string) error {
func configureInstallerVerbose(cmd *cobra.Command, args []string) error {
verbosiness := viper.GetBool("verbose")
quiet := viper.GetBool("quiet")
if quiet && verbosiness {
Expand All @@ -61,6 +60,16 @@ func configureInstaller(cmd *cobra.Command, args []string) error {
log.SetLevel(log.DebugLevel)
}

return nil
}

// configureInstaller configures cpackget installer for adding or removing pack/pdsc
func configureInstaller(cmd *cobra.Command, args []string) error {
err := configureInstallerVerbose(cmd, args)
if err != nil {
return err
}

targetPackRoot := viper.GetString("pack-root")
if targetPackRoot == installer.GetDefaultCmsisPackRoot() {
// If using the default pack root path and the public index is not found,
Expand Down
4 changes: 2 additions & 2 deletions cmd/commands/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ The referenced pack must be in its original/compressed form (.pack), and be pres
$ cpackget signature-create Vendor.Pack.1.2.3.pack -k private.key -c certificate.pem`,
Args: cobra.ExactArgs(1),
PersistentPreRunE: configureInstaller,
PersistentPreRunE: configureInstallerVerbose,
RunE: func(cmd *cobra.Command, args []string) error {
if signatureCreateflags.keyPath == "" {
if !signatureCreateflags.certOnly {
Expand Down Expand Up @@ -154,7 +154,7 @@ The referenced pack must be in its original/compressed form (.pack), and be pres
$ cpackget signature-verify Vendor.Pack.1.2.3.pack.signed`,
Args: cobra.ExactArgs(1),
PersistentPreRunE: configureInstaller,
PersistentPreRunE: configureInstallerVerbose,
RunE: func(cmd *cobra.Command, args []string) error {
if signatureVerifyflags.export && (signatureVerifyflags.skipCertValidation || signatureVerifyflags.skipInfo) {
log.Error("-e/--export does not need any other flags")
Expand Down
2 changes: 1 addition & 1 deletion cmd/cryptography/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func isPrivateKeyFromCertificate(cert *x509.Certificate, keyDER []byte, keyType
// from source vs an automated release.
func sanitizeVersionForSignature(version string) string {
v := sigVersionPrefix
if string(version[0]) != "v" {
if version != "" && string(version[0]) != "v" {
return v + "v" + version
}
return v + version
Expand Down

0 comments on commit 1a7f3c5

Please sign in to comment.