mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
fix flag inconsistency
This commit is contained in:
+5
-3
@@ -31,16 +31,18 @@ func NewInstallCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "install",
|
||||
Short: "Setup PMG config and aliases for package managers (npm, pnpm, pip, and more)",
|
||||
Long: "",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
fmt.Print(ui.GeneratePMGBanner(version.Version, version.Commit))
|
||||
|
||||
cfgPath, err := config.CreateConfig()
|
||||
if err != nil {
|
||||
if errors.Is(err, config.ErrConfigAlreadyExists) {
|
||||
fmt.Printf("PMG config already exists at %s\n", cfgPath)
|
||||
msg := fmt.Sprintf("⚠️ PMG config already exists at %s\n", cfgPath)
|
||||
ui.ShowWarning(msg)
|
||||
} else {
|
||||
return fmt.Errorf("failed to create config file: %w", err)
|
||||
er := fmt.Errorf("failed to create config file: %w", err)
|
||||
ui.ErrorExit(er)
|
||||
return er
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("📄 PMG config created at %s\n", cfgPath)
|
||||
|
||||
+5
-13
@@ -103,7 +103,7 @@ func CreateConfig() (string, error) {
|
||||
return "", fmt.Errorf("failed to prepare default config: %w", err)
|
||||
}
|
||||
|
||||
writeErr := writer.WriteConfigAs(cfgFile)
|
||||
writeErr := writer.SafeWriteConfigAs(cfgFile)
|
||||
|
||||
if writeErr != nil {
|
||||
var alreadyExistsErr viper.ConfigFileAlreadyExistsError
|
||||
@@ -180,18 +180,10 @@ func bindFlags(fs *pflag.FlagSet) {
|
||||
return
|
||||
}
|
||||
|
||||
// Helper binds a flag if it exists
|
||||
bind := func(key, flag string) {
|
||||
if f := fs.Lookup(flag); f != nil {
|
||||
_ = viper.BindPFlag(key, f)
|
||||
}
|
||||
}
|
||||
|
||||
bind("transitive", "transitive")
|
||||
bind("transitive_depth", "transitive-depth")
|
||||
bind("include_dev_dependencies", "include-dev-dependencies")
|
||||
bind("dry_run", "dry-run")
|
||||
bind("paranoid", "paranoid")
|
||||
fs.VisitAll(func(flag *pflag.Flag) {
|
||||
key := strings.ReplaceAll(flag.Name, "-", "_")
|
||||
_ = viper.BindPFlag(key, flag)
|
||||
})
|
||||
}
|
||||
|
||||
// Helper function to map the provided config for setting key/values in viper
|
||||
|
||||
@@ -128,8 +128,7 @@ func (a *AliasManager) Install() error {
|
||||
return fmt.Errorf("failed to update shell configs: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("✅ PMG aliases installed successfully!")
|
||||
fmt.Printf("📁 Created: %s\n", rcPath)
|
||||
fmt.Println("✅ PMG aliases installed successfully at", rcPath)
|
||||
fmt.Println("💡 Restart your terminal or source your shell to use the new aliases")
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user