mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	Fixed write-inplace with no expression
This commit is contained in:
		
							parent
							
								
									26742b2597
								
							
						
					
					
						commit
						bd0818c481
					
				| @ -42,14 +42,21 @@ func evaluateAll(cmd *cobra.Command, args []string) error { | |||||||
| 		colorsEnabled = true | 		colorsEnabled = true | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if writeInplace && len(args) < 2 { | 	firstFileIndex := -1 | ||||||
|  | 	if !nullInput && len(args) == 1 { | ||||||
|  | 		firstFileIndex = 0 | ||||||
|  | 	} else if len(args) > 1 { | ||||||
|  | 		firstFileIndex = 1 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if writeInplace && (firstFileIndex == -1) { | ||||||
| 		return fmt.Errorf("Write inplace flag only applicable when giving an expression and at least one file") | 		return fmt.Errorf("Write inplace flag only applicable when giving an expression and at least one file") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if writeInplace { | 	if writeInplace { | ||||||
| 		// only use colors if its forced | 		// only use colors if its forced | ||||||
| 		colorsEnabled = forceColor | 		colorsEnabled = forceColor | ||||||
| 		writeInPlaceHandler := yqlib.NewWriteInPlaceHandler(args[1]) | 		writeInPlaceHandler := yqlib.NewWriteInPlaceHandler(args[firstFileIndex]) | ||||||
| 		out, err = writeInPlaceHandler.CreateTempFile() | 		out, err = writeInPlaceHandler.CreateTempFile() | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
|  | |||||||
| @ -62,14 +62,21 @@ func evaluateSequence(cmd *cobra.Command, args []string) error { | |||||||
| 		colorsEnabled = true | 		colorsEnabled = true | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if writeInplace && len(args) < 2 { | 	firstFileIndex := -1 | ||||||
|  | 	if !nullInput && len(args) == 1 { | ||||||
|  | 		firstFileIndex = 0 | ||||||
|  | 	} else if len(args) > 1 { | ||||||
|  | 		firstFileIndex = 1 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if writeInplace && (firstFileIndex == -1) { | ||||||
| 		return fmt.Errorf("Write inplace flag only applicable when giving an expression and at least one file") | 		return fmt.Errorf("Write inplace flag only applicable when giving an expression and at least one file") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if writeInplace { | 	if writeInplace { | ||||||
| 		// only use colors if its forced | 		// only use colors if its forced | ||||||
| 		colorsEnabled = forceColor | 		colorsEnabled = forceColor | ||||||
| 		writeInPlaceHandler := yqlib.NewWriteInPlaceHandler(args[1]) | 		writeInPlaceHandler := yqlib.NewWriteInPlaceHandler(args[firstFileIndex]) | ||||||
| 		out, err = writeInPlaceHandler.CreateTempFile() | 		out, err = writeInPlaceHandler.CreateTempFile() | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user