mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
fix: npm command parser to extract package names
This commit is contained in:
+13
-16
@@ -59,23 +59,24 @@ func (npm *npmPackageManager) ParseCommand(args []string) (*ParsedCommand, error
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Check if this is an install command
|
||||
if !npm.isInstallCommand(args[0]) {
|
||||
return &ParsedCommand{
|
||||
Command: command,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Extract packages from args
|
||||
var packages []string
|
||||
for i := 1; i < len(args); i++ {
|
||||
arg := args[i]
|
||||
if !strings.HasPrefix(arg, "-") {
|
||||
packages = append(packages, arg)
|
||||
for idx, arg := range args {
|
||||
if slices.Contains(npm.Config.InstallCommands, arg) {
|
||||
// All subsequent args are packages except for flags
|
||||
for i := idx + 1; i < len(args); i++ {
|
||||
if strings.HasPrefix(args[i], "-") {
|
||||
continue
|
||||
}
|
||||
|
||||
packages = append(packages, args[i])
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// No packages specified
|
||||
// No packages found
|
||||
if len(packages) == 0 {
|
||||
return &ParsedCommand{
|
||||
Command: command,
|
||||
@@ -112,10 +113,6 @@ func (npm *npmPackageManager) ParseCommand(args []string) (*ParsedCommand, error
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (npm *npmPackageManager) isInstallCommand(cmd string) bool {
|
||||
return slices.Contains(npm.Config.InstallCommands, cmd)
|
||||
}
|
||||
|
||||
func npmParsePackageInfo(input string) (packageName, version string, err error) {
|
||||
if input == "" {
|
||||
return "", "", fmt.Errorf("package info cannot be empty")
|
||||
|
||||
Reference in New Issue
Block a user