1
1
/*
2
- * Copyright 2021-2023 the original author or authors.
2
+ * Copyright 2021-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .cli .command ;
18
18
19
+ import java .util .Optional ;
20
+
19
21
import org .jline .utils .AttributedStringBuilder ;
20
22
import org .jline .utils .AttributedStyle ;
21
23
22
24
import org .springframework .beans .BeansException ;
23
- import org .springframework .beans .factory .annotation .Autowired ;
24
25
import org .springframework .cli .merger .ai .OpenAiHandler ;
25
26
import org .springframework .cli .merger .ai .service .GenerateCodeAiService ;
26
27
import org .springframework .cli .util .TerminalMessage ;
@@ -39,15 +40,11 @@ public class AiCommands implements ApplicationContextAware {
39
40
40
41
private ApplicationContext applicationContext ;
41
42
42
- @ Autowired
43
- public AiCommands (TerminalMessage terminalMessage ) {
44
- this .terminalMessage = terminalMessage ;
45
- this .openAiHandler = new OpenAiHandler (new GenerateCodeAiService (this .terminalMessage ));
46
- }
47
-
48
- public AiCommands (OpenAiHandler openAiHandler , TerminalMessage terminalMessage ) {
43
+ public AiCommands (Optional <OpenAiHandler > openAiHandler , TerminalMessage terminalMessage ) {
49
44
this .terminalMessage = terminalMessage ;
50
- this .openAiHandler = openAiHandler ;
45
+ this .openAiHandler = openAiHandler .orElseGet (() -> {
46
+ return new OpenAiHandler (new GenerateCodeAiService (this .terminalMessage ));
47
+ });
51
48
}
52
49
53
50
@ Command (command = "add" , description = "Add code to the project from AI for a Spring project." )
0 commit comments