mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
refactor: add comment for cmd parse
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
packagev1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/package/v1"
|
packagev1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/package/v1"
|
||||||
"github.com/google/osv-scanner/pkg/lockfile"
|
"github.com/google/osv-scanner/pkg/lockfile"
|
||||||
|
"github.com/safedep/dry/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ExtractorConfig struct {
|
type ExtractorConfig struct {
|
||||||
@@ -52,7 +53,7 @@ func (e *extractor) ExtractManifest() ([]*packagev1.PackageVersion, error) {
|
|||||||
// Extract packages from this lockfile
|
// Extract packages from this lockfile
|
||||||
packages, err := e.extractFromLockfile(filePath)
|
packages, err := e.extractFromLockfile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Warning: failed to extract from %s: %v\n", filePath, err)
|
log.Warnf("failed to extract from %s: %v\n", filePath, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func (npm *npmPackageManager) ParseCommand(args []string) (*ParsedCommand, error
|
|||||||
|
|
||||||
command := Command{Exe: npm.Config.CommandName, Args: args}
|
command := Command{Exe: npm.Config.CommandName, Args: args}
|
||||||
|
|
||||||
// No command specified
|
// Since manifest-based installs like 'npm i' are now valid commands
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return &ParsedCommand{
|
return &ParsedCommand{
|
||||||
Command: command,
|
Command: command,
|
||||||
@@ -61,7 +61,7 @@ func (npm *npmPackageManager) ParseCommand(args []string) (*ParsedCommand, error
|
|||||||
var packages []string
|
var packages []string
|
||||||
var isManifestInstall bool
|
var isManifestInstall bool
|
||||||
var foundInstallCmd bool
|
var foundInstallCmd bool
|
||||||
|
|
||||||
for idx, arg := range args {
|
for idx, arg := range args {
|
||||||
if slices.Contains(npm.Config.InstallCommands, arg) {
|
if slices.Contains(npm.Config.InstallCommands, arg) {
|
||||||
foundInstallCmd = true
|
foundInstallCmd = true
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ func (pip *pipPackageManager) ParseCommand(args []string) (*ParsedCommand, error
|
|||||||
}
|
}
|
||||||
command := Command{Exe: pip.Config.CommandName, Args: args}
|
command := Command{Exe: pip.Config.CommandName, Args: args}
|
||||||
|
|
||||||
|
// Since manifest-based installs like 'npm i' are now valid commands
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return &ParsedCommand{
|
return &ParsedCommand{
|
||||||
Command: command,
|
Command: command,
|
||||||
@@ -60,7 +61,7 @@ func (pip *pipPackageManager) ParseCommand(args []string) (*ParsedCommand, error
|
|||||||
// Check for manifest-based installation flags
|
// Check for manifest-based installation flags
|
||||||
for i := idx + 1; i < len(args); i++ {
|
for i := idx + 1; i < len(args); i++ {
|
||||||
currentArg := args[i]
|
currentArg := args[i]
|
||||||
|
|
||||||
// Handle -r/--requirement flags
|
// Handle -r/--requirement flags
|
||||||
if currentArg == "-r" || currentArg == "--requirement" {
|
if currentArg == "-r" || currentArg == "--requirement" {
|
||||||
isManifestInstall = true
|
isManifestInstall = true
|
||||||
@@ -70,28 +71,28 @@ func (pip *pipPackageManager) ParseCommand(args []string) (*ParsedCommand, error
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle combined -r flag (e.g., -rrequirements.txt)
|
// Handle combined -r flag (e.g., -rrequirements.txt)
|
||||||
if strings.HasPrefix(currentArg, "-r") && len(currentArg) > 2 {
|
if strings.HasPrefix(currentArg, "-r") && len(currentArg) > 2 {
|
||||||
isManifestInstall = true
|
isManifestInstall = true
|
||||||
manifestFiles = append(manifestFiles, currentArg[2:])
|
manifestFiles = append(manifestFiles, currentArg[2:])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle other flags that indicate manifest installation
|
// Handle other flags that indicate manifest installation
|
||||||
if currentArg == "-e" || currentArg == "--editable" ||
|
if currentArg == "-e" || currentArg == "--editable" ||
|
||||||
currentArg == "-c" || currentArg == "--constraint" {
|
currentArg == "-c" || currentArg == "--constraint" {
|
||||||
if i+1 < len(args) {
|
if i+1 < len(args) {
|
||||||
i++ // skip the next argument
|
i++ // skip the next argument
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's a flag, skip it
|
// If it's a flag, skip it
|
||||||
if strings.HasPrefix(currentArg, "-") {
|
if strings.HasPrefix(currentArg, "-") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, it's a package name
|
// Otherwise, it's a package name
|
||||||
packages = append(packages, currentArg)
|
packages = append(packages, currentArg)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user