99use Stolt \LeanPackage \Analysers \NegatedExportIgnoreAnalyser ;
1010use Stolt \LeanPackage \Commands \Concerns \GeneratesGitattributesOptions ;
1111use Stolt \LeanPackage \Commands \Concerns \OutputOptions ;
12+ use Stolt \LeanPackage \Configuration \Factory ;
1213use Stolt \LeanPackage \Gitattributes \FileRepository as GitattributesFileRepository ;
1314use Symfony \Component \Console \Command \Command ;
1415use Symfony \Component \Console \Input \InputArgument ;
@@ -71,14 +72,11 @@ protected function configure(): void
7172
7273 protected function execute (InputInterface $ input , OutputInterface $ output ): int
7374 {
74- $ directory = (string ) $ input ->getArgument ('directory ' ) ?: \getcwd ();
75- $ forceCreation = (bool ) $ input ->getOption ('force ' );
75+ $ configuration = (new Factory ())->createCreateConfig ($ input );
7676
77- $ this ->analyser ->getActualExportIgnoreAnalyser ()->setDirectory ($ directory );
77+ $ this ->analyser ->getActualExportIgnoreAnalyser ()->setDirectory ($ configuration -> directory );
7878
79- $ isAgenticRun = $ this ->isAgenticRun ();
80-
81- $ generationFlavour = $ input ->getOption ('flavour ' ) ?: ClassicExportIgnoreAnalyser::EXPORT_IGNORE_CLASSIC ;
79+ $ generationFlavour = $ configuration ->flavour ?: ClassicExportIgnoreAnalyser::EXPORT_IGNORE_CLASSIC ;
8280
8381 if (!\in_array ($ generationFlavour , [ClassicExportIgnoreAnalyser::EXPORT_IGNORE_CLASSIC , NegatedExportIgnoreAnalyser::EXPORT_IGNORE_NEGATED ], true )) {
8482 $ output ->writeln ('<error>Invalid flavour specified. Use <info>classic</info> or <info>negated</info>.</error> ' );
@@ -92,9 +90,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9290
9391 $ gitattributesPath = $ this ->analyser ->getActualExportIgnoreAnalyser ()->getGitattributesFilePath ();
9492
95- if (\file_exists ($ gitattributesPath ) && $ forceCreation === false && $ this ->isDryRun ($ input ) !== true ) {
96- $ message = 'A .gitattributes file already exists. Use the update command to modify it. ' ;
97- if ($ isAgenticRun ) {
93+ if (\file_exists ($ gitattributesPath ) && $ configuration -> forceOverwrite === false && $ this ->isDryRun ($ input ) !== true ) {
94+ $ message = 'A .gitattributes file already exists. Use the update command or --force option to modify it. ' ;
95+ if ($ configuration -> isAgenticRun ) {
9896 $ this ->writeAgenticOutput ($ output , $ this ->getName (), false , $ message );
9997 } else {
10098 $ output ->writeln ($ message );
@@ -106,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
106104
107105 if ($ expected === '' ) {
108106 $ message = 'Unable to determine expected .gitattributes content for the given directory. ' ;
109- if ($ isAgenticRun ) {
107+ if ($ configuration -> isAgenticRun ) {
110108 $ this ->writeAgenticOutput ($ output , $ this ->getName (), false , $ message );
111109 } else {
112110 $ output ->writeln ($ message );
@@ -124,18 +122,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
124122 $ this ->repository ->createGitattributesFile ($ expected );
125123 } catch (Throwable $ e ) {
126124 $ message = 'Creation of .gitattributes file failed. ' ;
127- if ($ isAgenticRun ) {
125+ if ($ configuration -> isAgenticRun ) {
128126 $ this ->writeAgenticOutput ($ output , $ this ->getName (), false , $ message );
129127 } else {
130128 $ output ->writeln ($ message );
131129 }
132130 return self ::FAILURE ;
133131 }
134132
135- $ directory = \realpath ($ directory );
136- $ message = "A .gitattributes file has been created in { $ directory} . " ;
133+ $ directory = \realpath ($ configuration -> directory );
134+ $ message = "A .gitattributes file has been created in $ directory. " ;
137135
138- if ($ isAgenticRun ) {
136+ if ($ configuration -> isAgenticRun ) {
139137 $ this ->writeAgenticOutput ($ output , $ this ->getName (), true , $ message , ['gitattributes_file_path ' => $ gitattributesPath ]);
140138 } else {
141139 $ output ->writeln ($ message );
0 commit comments