2025-06-24 12:46:21 +05:30
|
|
|
package setup
|
|
|
|
|
|
|
|
|
|
import (
|
2025-08-21 23:01:30 +05:30
|
|
|
"fmt"
|
|
|
|
|
|
2025-06-24 12:46:21 +05:30
|
|
|
"github.com/safedep/pmg/internal/alias"
|
2025-08-21 23:01:30 +05:30
|
|
|
"github.com/safedep/pmg/internal/ui"
|
|
|
|
|
"github.com/safedep/pmg/internal/version"
|
2025-06-24 12:46:21 +05:30
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func NewSetupCommand() *cobra.Command {
|
|
|
|
|
setupCmd := &cobra.Command{
|
|
|
|
|
Use: "setup",
|
|
|
|
|
Short: "Manage PMG shell aliases and integration",
|
|
|
|
|
Long: "Setup and manage PMG shell aliases that allow you to use 'npm', 'pnpm', 'pip' commands through PMG's security wrapper.",
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
return cmd.Help()
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setupCmd.AddCommand(NewInstallCommand())
|
|
|
|
|
setupCmd.AddCommand(NewRemoveCommand())
|
|
|
|
|
|
|
|
|
|
return setupCmd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewInstallCommand() *cobra.Command {
|
|
|
|
|
return &cobra.Command{
|
|
|
|
|
Use: "install",
|
|
|
|
|
Short: "Install PMG aliases for package managers (npm, pnpm, pip)",
|
|
|
|
|
Long: "Creates ~/.pmg.rc with package manager aliases and sources it in your shell config files (.bashrc, .zshrc, config.fish)",
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2025-08-21 23:01:30 +05:30
|
|
|
fmt.Print(ui.GeneratePMGBanner(version.Version, version.Commit))
|
|
|
|
|
|
2025-06-24 12:46:21 +05:30
|
|
|
config := alias.DefaultConfig()
|
|
|
|
|
rcFileManager, err := alias.NewDefaultRcFileManager(config.RcFileName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2025-08-21 18:26:05 +05:30
|
|
|
|
|
|
|
|
aliasManager := alias.New(config, rcFileManager)
|
2025-06-24 12:46:21 +05:30
|
|
|
return aliasManager.Install()
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewRemoveCommand() *cobra.Command {
|
|
|
|
|
return &cobra.Command{
|
|
|
|
|
Use: "remove",
|
|
|
|
|
Short: "Removes pmg aliases from the user's shell config file.",
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2025-08-21 23:01:30 +05:30
|
|
|
fmt.Print(ui.GeneratePMGBanner(version.Version, version.Commit))
|
|
|
|
|
|
2025-06-24 12:46:21 +05:30
|
|
|
config := alias.DefaultConfig()
|
|
|
|
|
rcFileManager, err := alias.NewDefaultRcFileManager(config.RcFileName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2025-08-21 18:26:05 +05:30
|
|
|
|
|
|
|
|
aliasManager := alias.New(config, rcFileManager)
|
2025-06-24 12:46:21 +05:30
|
|
|
return aliasManager.Remove()
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|