2025-04-30 14:26:38 +05:30
|
|
|
package npm
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
_ "embed"
|
|
|
|
|
|
2025-05-15 16:50:59 +05:30
|
|
|
"github.com/safedep/dry/log"
|
|
|
|
|
"github.com/safedep/pmg/config"
|
|
|
|
|
"github.com/safedep/pmg/internal/ui"
|
2025-04-30 14:26:38 +05:30
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func NewNpmCommand() *cobra.Command {
|
2025-05-15 16:50:59 +05:30
|
|
|
return &cobra.Command{
|
2025-04-30 14:26:38 +05:30
|
|
|
Use: "npm [action] [package]",
|
2025-05-15 16:50:59 +05:30
|
|
|
Short: "Guard npm package manager",
|
2025-04-30 14:26:38 +05:30
|
|
|
DisableFlagParsing: true,
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2025-05-15 16:50:59 +05:30
|
|
|
config, err := config.FromContext(cmd.Context())
|
2025-04-30 14:26:38 +05:30
|
|
|
if err != nil {
|
2025-05-15 16:50:59 +05:30
|
|
|
ui.Fatalf("Failed to get config: %s", err)
|
2025-04-30 14:26:38 +05:30
|
|
|
}
|
|
|
|
|
|
2025-05-15 16:50:59 +05:30
|
|
|
err = executeNpmFlow(cmd.Context(), config, args)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorf("Failed to execute npm flow: %s", err)
|
2025-04-30 14:26:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|