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{
|
return &cobra.Command{
|
||||||
Use: "install",
|
Use: "install",
|
||||||
Short: "Setup PMG config and aliases for package managers (npm, pnpm, pip, and more)",
|
Short: "Setup PMG config and aliases for package managers (npm, pnpm, pip, and more)",
|
||||||
Long: "",
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
fmt.Print(ui.GeneratePMGBanner(version.Version, version.Commit))
|
fmt.Print(ui.GeneratePMGBanner(version.Version, version.Commit))
|
||||||
|
|
||||||
cfgPath, err := config.CreateConfig()
|
cfgPath, err := config.CreateConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, config.ErrConfigAlreadyExists) {
|
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 {
|
} 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 {
|
} else {
|
||||||
fmt.Printf("📄 PMG config created at %s\n", cfgPath)
|
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)
|
return "", fmt.Errorf("failed to prepare default config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
writeErr := writer.WriteConfigAs(cfgFile)
|
writeErr := writer.SafeWriteConfigAs(cfgFile)
|
||||||
|
|
||||||
if writeErr != nil {
|
if writeErr != nil {
|
||||||
var alreadyExistsErr viper.ConfigFileAlreadyExistsError
|
var alreadyExistsErr viper.ConfigFileAlreadyExistsError
|
||||||
@@ -180,18 +180,10 @@ func bindFlags(fs *pflag.FlagSet) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper binds a flag if it exists
|
fs.VisitAll(func(flag *pflag.Flag) {
|
||||||
bind := func(key, flag string) {
|
key := strings.ReplaceAll(flag.Name, "-", "_")
|
||||||
if f := fs.Lookup(flag); f != nil {
|
_ = viper.BindPFlag(key, flag)
|
||||||
_ = 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")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to map the provided config for setting key/values in viper
|
// 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)
|
return fmt.Errorf("failed to update shell configs: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("✅ PMG aliases installed successfully!")
|
fmt.Println("✅ PMG aliases installed successfully at", rcPath)
|
||||||
fmt.Printf("📁 Created: %s\n", rcPath)
|
|
||||||
fmt.Println("💡 Restart your terminal or source your shell to use the new aliases")
|
fmt.Println("💡 Restart your terminal or source your shell to use the new aliases")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
globalConfig = cfg
|
globalConfig = cfg
|
||||||
|
|
||||||
|
fmt.Printf("%+v: ", globalConfig)
|
||||||
log.InitZapLogger("pmg", "cli")
|
log.InitZapLogger("pmg", "cli")
|
||||||
cmd.SetContext(globalConfig.Inject(cmd.Context()))
|
cmd.SetContext(globalConfig.Inject(cmd.Context()))
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user