MCPcopy Index your code
hub / github.com/devspace-sh/devspace / addDevConfig

Method addDevConfig

cmd/init.go:677–786  ·  view source on GitHub ↗
(config *latest.Config, imageName, image string, port int, languageHandler *generator.LanguageHandler)

Source from the content-addressed store, hash-verified

675}
676
677func (cmd *InitCmd) addDevConfig(config *latest.Config, imageName, image string, port int, languageHandler *generator.LanguageHandler) error {
678 if config.Dev == nil {
679 config.Dev = map[string]*latest.DevPod{}
680 }
681
682 devConfig, ok := config.Dev[imageName]
683 if !ok {
684 devConfig = &latest.DevPod{}
685 config.Dev[imageName] = devConfig
686 }
687
688 devConfig.ImageSelector = image
689
690 if port > 0 {
691 localPort := port
692 if localPort < 1024 {
693 cmd.log.WriteString(logrus.InfoLevel, "\n")
694 cmd.log.Warn("Your application listens on a system port [0-1024]. Choose a forwarding-port to access your application via localhost.")
695
696 portString, err := cmd.log.Question(&survey.QuestionOptions{
697 Question: "Which forwarding port [1024-49151] do you want to use to access your application?",
698 DefaultValue: strconv.Itoa(localPort + 8000),
699 })
700 if err != nil {
701 return err
702 }
703
704 localPort, err = strconv.Atoi(portString)
705 if err != nil {
706 return errors.Errorf("Error parsing port '%s'", portString)
707 }
708 }
709
710 // Add dev.ports
711 portMapping := latest.PortMapping{
712 Port: fmt.Sprintf("%d", port),
713 }
714 if port != localPort {
715 portMapping = latest.PortMapping{
716 Port: fmt.Sprintf("%d:%d", localPort, port),
717 }
718 }
719
720 if devConfig.Ports == nil {
721 devConfig.Ports = []*latest.PortMapping{}
722 }
723 devConfig.Ports = append(devConfig.Ports, &portMapping)
724
725 if devConfig.Open == nil {
726 devConfig.Open = []*latest.OpenConfig{}
727 }
728 devConfig.Open = append(devConfig.Open, &latest.OpenConfig{
729 URL: "http://localhost:" + strconv.Itoa(localPort),
730 })
731 }
732
733 if devConfig.Sync == nil {
734 devConfig.Sync = []*latest.SyncConfig{}

Callers 1

initDevspaceMethod · 0.95

Calls 6

BoolFunction · 0.92
GetDevImageMethod · 0.80
WriteStringMethod · 0.65
QuestionMethod · 0.65
WarnMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected