@@ -333,31 +333,32 @@ func (optSet *OptionSet) SetDefaults() error {
333333		groupByValue [opt .Value ] =  append (groupByValue [opt .Value ], opt )
334334	}
335335
336- 	for  _ , opts  :=  range  groupByValue  {
337- 		// Sort the options by priority and whether or not a default is 
338- 		// set. This won't affect the value but represents correctness 
339- 		// from whence the value originated. 
340- 		slices .SortFunc (opts , func (a , b  * Option ) int  {
341- 			if  a .ValueSource  !=  b .ValueSource  {
342- 				for  _ , vs  :=  range  valueSourcePriority  {
343- 					if  a .ValueSource  ==  vs  {
344- 						return  - 1 
345- 					}
346- 					if  b .ValueSource  ==  vs  {
347- 						return  1 
348- 					}
336+ 	sortOptionByValueSourcePriorityOrDefault  :=  func (a , b  * Option ) int  {
337+ 		if  a .ValueSource  !=  b .ValueSource  {
338+ 			for  _ , vs  :=  range  valueSourcePriority  {
339+ 				if  a .ValueSource  ==  vs  {
340+ 					return  - 1 
349341				}
350- 			}
351- 			if  a .Default  !=  b .Default  {
352- 				if  a .Default  ==  ""  {
342+ 				if  b .ValueSource  ==  vs  {
353343					return  1 
354344				}
355- 				if  b .Default  ==  ""  {
356- 					return  - 1 
357- 				}
358345			}
359- 			return  0 
360- 		})
346+ 		}
347+ 		if  a .Default  !=  b .Default  {
348+ 			if  a .Default  ==  ""  {
349+ 				return  1 
350+ 			}
351+ 			if  b .Default  ==  ""  {
352+ 				return  - 1 
353+ 			}
354+ 		}
355+ 		return  0 
356+ 	}
357+ 	for  _ , opts  :=  range  groupByValue  {
358+ 		// Sort the options by priority and whether or not a default is 
359+ 		// set. This won't affect the value but represents correctness 
360+ 		// from whence the value originated. 
361+ 		slices .SortFunc (opts , sortOptionByValueSourcePriorityOrDefault )
361362
362363		// If the first option has a value source, then we don't need to 
363364		// set the default, but mark the source for all options. 
0 commit comments