dev: use cmd.Context inside custom command (#4496)
				
					
				
			This commit is contained in:
		
							parent
							
								
									b923d0fe7e
								
							
						
					
					
						commit
						2a1afc14cb
					
				| @ -22,7 +22,7 @@ func main() { | |||||||
| 	info := createBuildInfo() | 	info := createBuildInfo() | ||||||
| 
 | 
 | ||||||
| 	if err := commands.Execute(info); err != nil { | 	if err := commands.Execute(info); err != nil { | ||||||
| 		_, _ = fmt.Fprintf(os.Stderr, "failed executing command with error %v\n", err) | 		_, _ = fmt.Fprintf(os.Stderr, "Failed executing command with error: %v\n", err) | ||||||
| 		os.Exit(exitcodes.Failure) | 		os.Exit(exitcodes.Failure) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,7 +1,6 @@ | |||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" |  | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"log" | 	"log" | ||||||
| 	"os" | 	"os" | ||||||
| @ -27,7 +26,7 @@ func newCustomCommand(logger logutils.Log) *customCommand { | |||||||
| 
 | 
 | ||||||
| 	customCmd := &cobra.Command{ | 	customCmd := &cobra.Command{ | ||||||
| 		Use:     "custom", | 		Use:     "custom", | ||||||
| 		Short:   "Build a version of golangci-lint with custom linters.", | 		Short:   "Build a version of golangci-lint with custom linters", | ||||||
| 		Args:    cobra.NoArgs, | 		Args:    cobra.NoArgs, | ||||||
| 		PreRunE: c.preRunE, | 		PreRunE: c.preRunE, | ||||||
| 		RunE:    c.runE, | 		RunE:    c.runE, | ||||||
| @ -54,9 +53,7 @@ func (c *customCommand) preRunE(_ *cobra.Command, _ []string) error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *customCommand) runE(_ *cobra.Command, _ []string) error { | func (c *customCommand) runE(cmd *cobra.Command, _ []string) error { | ||||||
| 	ctx := context.Background() |  | ||||||
| 
 |  | ||||||
| 	tmp, err := os.MkdirTemp(os.TempDir(), "custom-gcl") | 	tmp, err := os.MkdirTemp(os.TempDir(), "custom-gcl") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return fmt.Errorf("create temporary directory: %w", err) | 		return fmt.Errorf("create temporary directory: %w", err) | ||||||
| @ -72,7 +69,7 @@ func (c *customCommand) runE(_ *cobra.Command, _ []string) error { | |||||||
| 		_ = os.RemoveAll(tmp) | 		_ = os.RemoveAll(tmp) | ||||||
| 	}() | 	}() | ||||||
| 
 | 
 | ||||||
| 	err = internal.NewBuilder(c.log, c.cfg, tmp).Build(ctx) | 	err = internal.NewBuilder(c.log, c.cfg, tmp).Build(cmd.Context()) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return fmt.Errorf("build process: %w", err) | 		return fmt.Errorf("build process: %w", err) | ||||||
| 	} | 	} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Oleksandr Redko
						Oleksandr Redko