diff --git a/pkg/commands/dependency.go b/pkg/commands/dependency.go index 81a440d..b1fa190 100644 --- a/pkg/commands/dependency.go +++ b/pkg/commands/dependency.go @@ -45,6 +45,19 @@ func KindFlagMap() map[string]string { } } +type KindFlag struct { + Kind string + Flag string +} + +func KindFlags() []KindFlag { + return []KindFlag{ + {Kind: "prod", Flag: "--save-prod"}, + {Kind: "dev", Flag: "--save-dev"}, + {Kind: "optional", Flag: "--save-optional"}, + } +} + func (d *Dependency) kindKey() string { return KindKeyMap()[d.Kind] } diff --git a/pkg/gui/dependencies_panel.go b/pkg/gui/dependencies_panel.go index 867c528..7a5e71b 100644 --- a/pkg/gui/dependencies_panel.go +++ b/pkg/gui/dependencies_panel.go @@ -134,13 +134,13 @@ func (gui *Gui) wrappedDependencyHandler(f func(*commands.Dependency) error) fun func (gui *Gui) handleChangeDepType(dep *commands.Dependency) error { kindKeyMap := commands.KindKeyMap() - kindFlagMap := commands.KindFlagMap() - menuItems := make([]*menuItem, 0, len(commands.KindKeyMap())) - for kind := range kindFlagMap { - kind := kind - cmdStr := fmt.Sprintf("npm install %s %s", kindFlagMap[kind], dep.Name) + kindFlags := commands.KindFlags() + menuItems := make([]*menuItem, 0, len(kindFlags)) + for _, kindFlag := range kindFlags { + kindFlag := kindFlag + cmdStr := fmt.Sprintf("npm install %s %s", kindFlag.Flag, dep.Name) menuItems = append(menuItems, &menuItem{ - displayStrings: []string{kindKeyMap[kind], utils.ColoredString(cmdStr, color.FgYellow)}, + displayStrings: []string{kindKeyMap[kindFlag.Kind], utils.ColoredString(cmdStr, color.FgYellow)}, onPress: func() error { return gui.newMainCommand(cmdStr, dep.ID()) }, @@ -161,13 +161,13 @@ func (gui *Gui) handleAddDependency(dep *commands.Dependency) error { } kindKeyMap := commands.KindKeyMap() - kindFlagMap := commands.KindFlagMap() - menuItems := make([]*menuItem, 0, len(commands.KindKeyMap())) - for kind := range kindFlagMap { - kind := kind - cmdStr := fmt.Sprintf("npm install %s", kindFlagMap[kind]) + kindFlags := commands.KindFlags() + menuItems := make([]*menuItem, 0, len(kindFlags)) + for _, kindFlag := range kindFlags { + kindFlag := kindFlag + cmdStr := fmt.Sprintf("npm install %s", kindFlag.Flag) menuItems = append(menuItems, &menuItem{ - displayStrings: []string{kindKeyMap[kind], utils.ColoredString(cmdStr, color.FgYellow)}, + displayStrings: []string{kindKeyMap[kindFlag.Kind], utils.ColoredString(cmdStr, color.FgYellow)}, onPress: func() error { return prompt(cmdStr) },