@@ -9,13 +9,13 @@ class DataExtractCommand extends Command
99{
1010 public $ signature = 'data:extract ' ;
1111
12- public $ description = 'Extract data based on predefined instructions ' ;
12+ public $ description = 'Extract data based on predefined options ' ;
1313
14- public array $ instructions = [];
14+ public array $ options = [];
1515
1616 public function __construct ()
1717 {
18- $ this ->instructions = config ('data-extractor.instructions ' , []);
18+ $ this ->options = config ('data-extractor.options ' , []);
1919
2020 parent ::__construct ();
2121 }
@@ -28,21 +28,21 @@ public function handle(): int
2828 return self ::FAILURE ;
2929 }
3030
31- if ($ this ->validateInstructions () === false ) {
31+ if ($ this ->validateOptions () === false ) {
3232 return self ::FAILURE ;
3333 }
3434
35- $ selectedInstructions = $ this ->promptInstructions ();
35+ $ selectedOptions = $ this ->promptOptions ();
3636
37- $ id = $ this ->promptModelId ($ selectedInstructions );
37+ $ id = $ this ->promptModelId ($ selectedOptions );
3838
3939 if ($ id <= 0 ) {
4040 return self ::FAILURE ;
4141 }
4242
43- $ selectedSource = $ selectedInstructions ['source ' ] ?? null ;
43+ $ selectedSource = $ selectedOptions ['source ' ] ?? null ;
4444 if (! $ selectedSource ) {
45- $ this ->error ('No source specified in the selected instruction . ' );
45+ $ this ->error ('No source specified in the selected option . ' );
4646
4747 return self ::FAILURE ;
4848 }
@@ -88,39 +88,39 @@ public function handle(): int
8888 return self ::SUCCESS ;
8989 }
9090
91- protected function validateInstructions (): bool
91+ protected function validateOptions (): bool
9292 {
93- if (empty ($ this ->instructions )) {
94- $ this ->error ('No instructions found in the configuration. ' );
93+ if (empty ($ this ->options )) {
94+ $ this ->error ('No options found in the configuration. ' );
9595
9696 return false ;
9797 }
9898
9999 $ sourceConnections = array_keys (config ('data-extractor.source ' ));
100100
101- foreach ($ this ->instructions as $ instruction ) {
102- if (empty ($ instruction ['name ' ]) || empty ($ instruction ['source ' ]) || empty ($ instruction ['export ' ])) {
103- $ this ->error ('Invalid instruction format. Each instruction must have a name, source, and export configuration. ' );
101+ foreach ($ this ->options as $ option ) {
102+ if (empty ($ option ['name ' ]) || empty ($ option ['source ' ]) || empty ($ option ['export ' ])) {
103+ $ this ->error ('Invalid option format. Each option must have a name, source, and export configuration. ' );
104104
105105 return false ;
106106 }
107107
108- if (! in_array ($ instruction ['export ' ]['format ' ], Export::FORMATS )) {
109- $ this ->error ('Invalid export format in instruction : ' .$ instruction ['name ' ]);
108+ if (! in_array ($ option ['export ' ]['format ' ], Export::FORMATS )) {
109+ $ this ->error ('Invalid export format in option : ' .$ option ['name ' ]);
110110
111111 return false ;
112112 }
113113
114- if (! isset ($ instruction ['source ' ]) || ! is_string ($ instruction ['source ' ]) || ! in_array ($ instruction ['source ' ], $ sourceConnections )) {
115- $ this ->error ('Invalid source specified in instruction : ' .$ instruction ['name ' ]);
114+ if (! isset ($ option ['source ' ]) || ! is_string ($ option ['source ' ]) || ! in_array ($ option ['source ' ], $ sourceConnections )) {
115+ $ this ->error ('Invalid source specified in option : ' .$ option ['name ' ]);
116116
117117 return false ;
118118 }
119119
120- $ selectedSource = config ("data-extractor.source. {$ instruction ['source ' ]}" , []);
120+ $ selectedSource = config ("data-extractor.source. {$ option ['source ' ]}" , []);
121121
122122 if (! isset ($ selectedSource ['model ' ])) {
123- $ this ->error ('Invalid model configuration in source: ' .$ instruction ['source ' ]);
123+ $ this ->error ('Invalid model configuration in source: ' .$ option ['source ' ]);
124124
125125 return false ;
126126 }
@@ -129,46 +129,46 @@ protected function validateInstructions(): bool
129129 return true ;
130130 }
131131
132- protected function promptInstructions (): array
132+ protected function promptOptions (): array
133133 {
134134 $ this ->table (
135135 ['Name ' , 'Description ' , 'Export Format ' ],
136- array_map (function ($ instruction ) {
136+ array_map (function ($ option ) {
137137 return [
138- $ instruction ['name ' ],
139- $ instruction ['description ' ] ?? 'N/A ' ,
140- $ instruction ['export ' ]['format ' ],
138+ $ option ['name ' ],
139+ $ option ['description ' ] ?? 'N/A ' ,
140+ $ option ['export ' ]['format ' ],
141141 ];
142- }, $ this ->instructions )
142+ }, $ this ->options )
143143 );
144144
145- $ instructionNames = array_column ($ this ->instructions , 'name ' );
145+ $ optionNames = array_column ($ this ->options , 'name ' );
146146
147147 $ selectedKey = array_keys ($ this ->choice (
148- 'Select an instruction to execute ' ,
149- $ instructionNames ,
148+ 'Select an option to execute ' ,
149+ $ optionNames ,
150150 null ,
151151 null ,
152152 true
153153 ));
154154
155- return $ this ->instructions [$ selectedKey [0 ]];
155+ return $ this ->options [$ selectedKey [0 ]];
156156 }
157157
158- protected function promptModelId ($ instruction ): int
158+ protected function promptModelId ($ option ): int
159159 {
160- $ source = $ instruction ['source ' ] ?? null ;
160+ $ source = $ option ['source ' ] ?? null ;
161161
162162 if (! $ source || ! is_string ($ source )) {
163- $ this ->error ('Invalid source specified in the instruction . ' );
163+ $ this ->error ('Invalid source specified in the option . ' );
164164
165165 return 0 ;
166166 }
167167
168168 $ modelClass = config ("data-extractor.source. $ source.model " );
169169
170170 if (! $ modelClass || ! class_exists ($ modelClass )) {
171- $ this ->error ('Invalid model class specified in the instruction source. ' );
171+ $ this ->error ('Invalid model class specified in the option source. ' );
172172
173173 return 0 ;
174174 }
0 commit comments