mirror of
				https://github.com/redhat-developer/odo.git
				synced 2025-10-19 03:06:19 +03:00 
			
		
		
		
	 6ed95b7e6f
			
		
	
	6ed95b7e6f
	
	
	
		
			
			* Allow using the '--run-on' flag with 'odo describe component' * Add "platform" to the ForwardedPort output * Move RunningMode* structs to a dedicated file and add (tested) method for merging running modes * Add RunningOn field to the Component API * Make component#GetRunningModes able to return all modes for all specified platforms * Do not display the namespace from NoComponentFoundError if no namespace is set * Add more validation logic to the 'describe component' CLI * Update 'odo describe component' logic for Devfile-based component * Update 'odo describe component' logic for name-based component This checks for the component with such name on all platforms. If it finds several components on both platforms, it needs to extract Devfile information from those resources. To do so, it checks if the relevant labels (project type and name) are matching. It errors out if they do not match, because this would imply that we don't know what to display as Devfile information. * Conditionally display "running on" information in human-readable output. This is displayed only if the "run-on" feature is enabled. * Implement GetAllResourcesFromSelector in the PodmanCli client * Add more unit tests * Update integration tests * fixup! Update integration tests * fixup! fixup! Update integration tests
		
			
				
	
	
		
			80 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package api
 | |
| 
 | |
| import (
 | |
| 	"sort"
 | |
| 	"strings"
 | |
| 
 | |
| 	"golang.org/x/text/cases"
 | |
| 	"golang.org/x/text/language"
 | |
| )
 | |
| 
 | |
| type RunningMode string
 | |
| type RunningModes map[RunningMode]bool
 | |
| 
 | |
| const (
 | |
| 	RunningModeDev    RunningMode = "dev"
 | |
| 	RunningModeDeploy RunningMode = "deploy"
 | |
| )
 | |
| 
 | |
| func NewRunningModes() RunningModes {
 | |
| 	return RunningModes{
 | |
| 		RunningModeDev:    false,
 | |
| 		RunningModeDeploy: false,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // AddRunningMode sets a running mode as true
 | |
| func (o RunningModes) AddRunningMode(mode RunningMode) {
 | |
| 	o[mode] = true
 | |
| }
 | |
| 
 | |
| func (o RunningModes) String() string {
 | |
| 	strs := make([]string, 0, len(o))
 | |
| 	caser := cases.Title(language.Und)
 | |
| 	for s, v := range o {
 | |
| 		if v {
 | |
| 			strs = append(strs, caser.String(string(s)))
 | |
| 		}
 | |
| 	}
 | |
| 	if len(strs) == 0 {
 | |
| 		return "None"
 | |
| 	}
 | |
| 	sort.Sort(sort.Reverse(sort.StringSlice(strs)))
 | |
| 	return strings.Join(strs, ", ")
 | |
| }
 | |
| 
 | |
| // MergeRunningModes returns a new RunningModes map which is the result of merging all the running modes from each platform, from the map specified.
 | |
| func MergeRunningModes(m map[string]RunningModes) RunningModes {
 | |
| 	if m == nil {
 | |
| 		return nil
 | |
| 	}
 | |
| 
 | |
| 	rm := NewRunningModes()
 | |
| 
 | |
| 	getMergedValueForMode := func(runningMode RunningMode) bool {
 | |
| 		for _, modeMap := range m {
 | |
| 			for mode, val := range modeMap {
 | |
| 				if mode != runningMode {
 | |
| 					continue
 | |
| 				}
 | |
| 				if val {
 | |
| 					return val
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		return false
 | |
| 	}
 | |
| 
 | |
| 	// Dev
 | |
| 	if getMergedValueForMode(RunningModeDev) {
 | |
| 		rm.AddRunningMode(RunningModeDev)
 | |
| 	}
 | |
| 
 | |
| 	// Deploy
 | |
| 	if getMergedValueForMode(RunningModeDeploy) {
 | |
| 		rm.AddRunningMode(RunningModeDeploy)
 | |
| 	}
 | |
| 
 | |
| 	return rm
 | |
| }
 |