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

Method SetDevSpaceRoot

pkg/devspace/config/loader/loader.go:614–665  ·  view source on GitHub ↗

SetDevSpaceRoot checks the current directory and all parent directories for a .devspace folder with a config and sets the current working directory accordingly

(log log.Logger)

Source from the content-addressed store, hash-verified

612
613// SetDevSpaceRoot checks the current directory and all parent directories for a .devspace folder with a config and sets the current working directory accordingly
614func (l *configLoader) SetDevSpaceRoot(log log.Logger) (bool, error) {
615 if l.absConfigPath != "" {
616 configExists := configExistsInPath(l.absConfigPath)
617 if !configExists {
618 return configExists, nil
619 }
620
621 err := os.Chdir(filepath.Dir(l.absConfigPath))
622 if err != nil {
623 return false, err
624 }
625
626 return true, nil
627 }
628
629 cwd, err := os.Getwd()
630 if err != nil {
631 return false, err
632 }
633
634 originalCwd := cwd
635 homeDir, err := homedir.Dir()
636 if err != nil {
637 return false, err
638 }
639
640 lastLength := 0
641 for len(cwd) != lastLength {
642 if cwd != homeDir {
643 configExists := configExistsInPath(filepath.Join(cwd, constants.DefaultConfigPath))
644 if configExists {
645 // Change working directory
646 err = os.Chdir(cwd)
647 if err != nil {
648 return false, err
649 }
650
651 // Notify user that we are not using the current working directory
652 if originalCwd != cwd {
653 log.Infof("Using devspace config in %s", filepath.ToSlash(cwd))
654 }
655
656 return true, nil
657 }
658 }
659
660 lastLength = len(cwd)
661 cwd = filepath.Dir(cwd)
662 }
663
664 return false, nil
665}
666
667func ConfigPath(configPath string) string {
668 path := constants.DefaultConfigPath

Callers 1

testSetDevSpaceRootFunction · 0.95

Calls 2

configExistsInPathFunction · 0.85
InfofMethod · 0.45

Tested by 1

testSetDevSpaceRootFunction · 0.76