mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
feat: add setup & remove cmd for better UX (#43)
* feat: add setup & remove cmd for better UX * refactor(alias): improve separation of concerns and fix shell sourcing * chore: remove extra/unused folder * refactor: introduce separate files for shells * fix: use temp files for safe shell config modification
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"github.com/safedep/pmg/internal/alias"
|
||||
"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 {
|
||||
config := alias.DefaultConfig()
|
||||
rcFileManager, err := alias.NewDefaultRcFileManager(config.RcFileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
aliasManager := alias.New(*config, rcFileManager)
|
||||
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 {
|
||||
config := alias.DefaultConfig()
|
||||
rcFileManager, err := alias.NewDefaultRcFileManager(config.RcFileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
aliasManager := alias.New(*config, rcFileManager)
|
||||
return aliasManager.Remove()
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user