4242#include " IO.h"
4343
4444namespace fs = std::filesystem;
45- constexpr int kCLIError = 610 ;
46- constexpr int kInvalidWorkingDirectoryError = 640 ;
45+ constexpr int CLI_ERROR = 610 ;
46+ constexpr int INVALID_WORKING_DIRECTORY_ERROR = 640 ;
4747
4848std::string add_text_color (const std::array<int , 3 >& rgb) {
4949 if (isatty (STDOUT_FILENO ) && !IO_redirectedSTDOUT) {
50- return " \033 [38;2;" + std::to_string (rgb.at (0 )) + " ;" + std::to_string (rgb.at (1 )) + " ;" + std::to_string (rgb.at (2 )) + " m" ;
50+ return " \033 [38;2;" + std::to_string (rgb.at (0 )) + " ;" + std::to_string (rgb.at (1 )) + " ;" +
51+ std::to_string (rgb.at (2 )) + " m" ;
5152 }
5253 return {};
5354}
@@ -64,19 +65,32 @@ CLI::CLI(std::span<const char*> args, int* worldrank) {
6465 init_print ();
6566
6667 po::options_description flags (" Valid command line flags" );
67- flags.add_options ()(" help,h" , " show help" )(
68- " geometry,g" , po::value<std::string>(&arg_geom)->value_name (" [ --geom ]" )->required (), " geometry file" )(
69- " loadcase,l" , po::value<std::string>(&arg_load)->value_name (" [ --load ]" )->required (), " load case" )(
70- " materialconfig,m" , po::value<std::string>(&arg_material)->value_name (" [ --material ]" )->required (), " material config" )(
71- " numericsconfig,n" , po::value<std::string>(&arg_numerics)->value_name (" [ --numerics ]" ), " numerics config" )(
72- " jobname,j" , po::value<std::string>(&arg_jobname)->value_name (" [ --job ]" ), " job name" )(
73- " workingdirectory,w" , po::value<std::string>(&arg_wd)->value_name (" [ --wd ]" ), " working directory" )(
74- " wd" , po::value<std::string>(&arg_wd), " alias" )
68+ flags.add_options ()(" help,h" , " show help" );
69+ flags.add_options ()(" geometry,g" ,
70+ po::value<std::string>(&arg_geom)->value_name (" [ --geom ]" )->required (),
71+ " geometry file" );
72+ flags.add_options ()(" loadcase,l" ,
73+ po::value<std::string>(&arg_load)->value_name (" [ --load ]" )->required (),
74+ " load case" );
75+ flags.add_options ()(" materialconfig,m" ,
76+ po::value<std::string>(&arg_material)->value_name (" [ --material ]" )->required (),
77+ " material config" );
78+ flags.add_options ()(" numericsconfig,n" ,
79+ po::value<std::string>(&arg_numerics)->value_name (" [ --numerics ]" ),
80+ " numerics config" );
81+ flags.add_options ()(" jobname,j" ,
82+ po::value<std::string>(&arg_jobname)->value_name (" [ --job ]" ),
83+ " job name" );
84+ flags.add_options ()(" workingdirectory,w" ,
85+ po::value<std::string>(&arg_wd)->value_name (" [ --wd ]" ),
86+ " working directory" );
87+ flags.add_options ()(" wd" , po::value<std::string>(&arg_wd), " alias" );
7588#if defined(GRID) || defined(TEST)
76- (" restart,r" , po::value<int >(&arg_rs)->value_name (" [ --rs ]" ), " restart increment" )(
77- " rs" , po::value<int >(&arg_rs), " alias" )
89+ flags.add_options ()(" restart,r" ,
90+ po::value<int >(&arg_rs)->value_name (" [ --rs ]" ),
91+ " restart increment" );
92+ flags.add_options ()(" rs" , po::value<int >(&arg_rs), " alias" );
7893#endif
79- ;
8094 po::variables_map vm;
8195
8296 /* *
@@ -127,7 +141,7 @@ CLI::CLI(std::span<const char*> args, int* worldrank) {
127141
128142 po::notify (vm);
129143 } catch (const boost::program_options::error& e) {
130- IO::error (kCLIError , std::string (" Command line error: " ) + e.what ());
144+ IO::error (CLI_ERROR , std::string (" Command line error: " ) + e.what ());
131145 }
132146
133147 geom_path = remove_leading_equal (arg_geom);
@@ -150,13 +164,13 @@ CLI::CLI(std::span<const char*> args, int* worldrank) {
150164 try {
151165 fs::current_path (working_directory);
152166 } catch (const fs::filesystem_error&) {
153- IO::error (kInvalidWorkingDirectoryError , working_directory);
167+ IO::error (INVALID_WORKING_DIRECTORY_ERROR , working_directory);
154168 }
155169 }
156170
157171 if (vm.count (" restart" )) {
158172 if (arg_rs < 0 ) {
159- IO::error (kCLIError , std::string (" invalid value for --restart: " ) + std::to_string (arg_rs));
173+ IO::error (CLI_ERROR , std::string (" invalid value for --restart: " ) + std::to_string (arg_rs));
160174 }
161175 restart_inc = arg_rs;
162176 }
@@ -170,35 +184,35 @@ CLI::CLI(std::span<const char*> args, int* worldrank) {
170184 if (ec)
171185 throw std::runtime_error (" boost hostname collection error: " + ec.message ());
172186
173- cout << " Host name: " << hostname << std::endl ;
174- cout << " User name: " << get_username () << std::endl << std::endl ;
187+ cout << " Host name: " << hostname << " \n " ;
188+ cout << " User name: " << get_username () << " \n\n " ;
175189 cout << " Command line call: " ;
176190 for (auto & arg : args) {
177191 cout << arg << " " ;
178192 }
179- cout << std::endl ;
180- cout << " Working directory: " << fs::current_path ().string () << std::endl ;
181- cout << " Geometry: " << geom_path << std::endl ;
182- cout << " Load case: " << loadfile_path << std::endl ;
183- cout << " Material config: " << material_path << std::endl ;
193+ cout << " \n " ;
194+ cout << " Working directory: " << fs::current_path ().string () << " \n " ;
195+ cout << " Geometry: " << geom_path << " \n " ;
196+ cout << " Load case: " << loadfile_path << " \n " ;
197+ cout << " Material config: " << material_path << " \n " ;
184198 if (vm.count (" numericsconfig" )) {
185- cout << " Numerics config: " << numerics_path << std::endl ;
199+ cout << " Numerics config: " << numerics_path << " \n " ;
186200 }
187- cout << " Job name: " << jobname << std::endl ;
188- cout << " Job ID: " << uuid << std::endl ;
201+ cout << " Job name: " << jobname << " \n " ;
202+ cout << " Job ID: " << uuid << " \n " ;
189203 if (restart_inc != -1 ) {
190204 cout << " Restart increment: " << restart_inc << std::endl;
191205 }
192206}
193207
194208void CLI::init_print () {
195209#ifdef DEBUG
196- constexpr std::array<int , 3 > red = {255 , 0 , 0 };
197- cout << add_text_color (red );
198- cout << " debug version - debug version - debug version - debug version - debug version" << std::endl ;
210+ constexpr std::array<int , 3 > RED = {255 , 0 , 0 };
211+ cout << add_text_color (RED );
212+ cout << " debug version - debug version - debug version - debug version - debug version\n " ;
199213#else
200- constexpr std::array<int , 3 > damask_blue = {67 , 128 , 208 };
201- cout << add_text_color (damask_blue );
214+ constexpr std::array<int , 3 > DAMASK_BLUE = {67 , 128 , 208 };
215+ cout << add_text_color (DAMASK_BLUE );
202216#endif
203217 cout << R"(
204218 _/_/_/ _/_/ _/ _/ _/_/ _/_/_/ _/ _/ _/_/_/
@@ -210,62 +224,70 @@ void CLI::init_print() {
210224)" ;
211225
212226#ifdef GRID
213- constexpr std::array<int , 3 > damask_green = {123 , 207 , 68 };
214- cout << add_text_color (damask_green );
215- cout << " Grid solver" << std::endl << std::endl ;
227+ constexpr std::array<int , 3 > DAMASK_GREEN = {123 , 207 , 68 };
228+ cout << add_text_color (DAMASK_GREEN );
229+ cout << " Grid solver\n\n " ;
216230#elif defined(MESH)
217- constexpr std::array<int , 3 > damask_orange = {230 , 150 , 68 };
218- cout << add_text_color (damask_orange );
219- cout << " Mesh solver" << std::endl << std::endl ;
231+ constexpr std::array<int , 3 > DAMASK_ORANGE = {230 , 150 , 68 };
232+ cout << add_text_color (DAMASK_ORANGE );
233+ cout << " Mesh solver\n\n " ;
220234#endif
221235
222236#ifdef DEBUG
223- cout << add_text_color (red );
224- cout << " debug version - debug version - debug version - debug version - debug version" << std::endl << std::endl ;
237+ cout << add_text_color (RED );
238+ cout << " debug version - debug version - debug version - debug version - debug version\n\n " ;
225239#endif
226240
227241 cout << reset_text_color ();
228- cout << " F. Roters et al., Computational Materials Science 158:420–478, 2019" << std::endl
229- << " https://doi.org/10.1016/j.commatsci.2018.04.030" << std::endl
230- << std::endl;
231-
232- #if PETSC_VERSION_MAJOR != 3 || PETSC_VERSION_MINOR < PETSC_MINOR_MIN || PETSC_VERSION_MINOR > PETSC_MINOR_MAX
233- #error "-- UNSUPPORTED PETSc VERSION --- UNSUPPORTED PETSc VERSION --- UNSUPPORTED PETSc VERSION ---"
242+ cout << " F. Roters et al., Computational Materials Science 158:420–478, 2019\n "
243+ << " https://doi.org/10.1016/j.commatsci.2018.04.030\n\n " ;
244+
245+ #if PETSC_VERSION_MAJOR != 3
246+ #error "-- UNSUPPORTED PETSc VERSION ---"
247+ #elif PETSC_VERSION_MINOR < PETSC_MINOR_MIN
248+ #error "-- UNSUPPORTED PETSc VERSION ---"
249+ #elif PETSC_VERSION_MINOR > PETSC_MINOR_MAX
250+ #error "-- UNSUPPORTED PETSc VERSION ---"
234251#else
235- cout << " S. Balay et al., PETSc/TAO User Manual Revision " << PETSC_VERSION_MAJOR << " ." << PETSC_VERSION_MINOR << std::endl;
252+ cout << " S. Balay et al., PETSc/TAO User Manual Revision " << PETSC_VERSION_MAJOR << " ."
253+ << PETSC_VERSION_MINOR << " \n " ;
236254#if PETSC_VERSION_MINOR == 19
237- cout << " https://doi.org/10.2172/1968587" << endl ;
255+ cout << " https://doi.org/10.2172/1968587\n " ;
238256#elif PETSC_VERSION_MINOR == 20
239- cout << " https://doi.org/10.2172/2205494" << endl ;
257+ cout << " https://doi.org/10.2172/2205494\n " ;
240258#elif PETSC_VERSION_MINOR == 21
241- cout << " https://doi.org/10.2172/2337606" << endl ;
259+ cout << " https://doi.org/10.2172/2337606\n " ;
242260#elif PETSC_VERSION_MINOR == 22
243- cout << " https://doi.org/10.2172/2476320" << endl ;
261+ cout << " https://doi.org/10.2172/2476320\n " ;
244262#elif PETSC_VERSION_MINOR == 23
245- cout << " https://doi.org/10.2172/2565610" << endl ;
263+ cout << " https://doi.org/10.2172/2565610\n " ;
246264#elif PETSC_VERSION_MINOR == 24
247- cout << " https://doi.org/10.2172/2998643" << endl ;
265+ cout << " https://doi.org/10.2172/2998643\n " ;
248266#elif PETSC_VERSION_MINOR == 25
249- cout << " https://doi.org/10.2172/3025790" << endl ;
267+ cout << " https://doi.org/10.2172/3025790\n " ;
250268#endif
251- cout << endl ;
269+ cout << " \n " ;
252270#endif
253271
254- cout << " Version: " << DAMASK_VERSION << std::endl << std::endl ;
272+ cout << " Version: " << DAMASK_VERSION << " \n\n " ;
255273 cout << " Compiled with:" ;
256274#if defined(__clang__)
257- cout << " Clang version " << __clang_major__ << " ." << __clang_minor__ << " ." << __clang_patchlevel__ << std::endl;
275+ cout << " Clang version " << __clang_major__ << " ." << __clang_minor__ << " ."
276+ << __clang_patchlevel__ << std::endl;
258277#elif defined(__GNUC__)
259- cout << " GCC version " << __GNUC__ << " ." << __GNUC_MINOR__ << " ." << __GNUC_PATCHLEVEL__ << std::endl;
278+ cout << " GCC version " << __GNUC__ << " ." << __GNUC_MINOR__ << " ." << __GNUC_PATCHLEVEL__
279+ << std::endl;
260280#elif defined(__INTEL_COMPILER)
261- cout << " Intel Compiler version " << __INTEL_COMPILER << " ." << __INTEL_COMPILER_UPDATE << std::endl;
281+ cout << " Intel Compiler version " << __INTEL_COMPILER << " ." << __INTEL_COMPILER_UPDATE
282+ << std::endl;
262283#endif
263284 F_printCompileOptions ();
264- cout << std::endl ;
265- cout << " PETSc version: " << PETSC_VERSION_MAJOR << " . " << PETSC_VERSION_MINOR << " . " << PETSC_VERSION_SUBMINOR << std::endl
266- << std::endl ;
285+ cout << " \n " ;
286+ cout << " PETSc version: "
287+ << PETSC_VERSION_MAJOR << " . " << PETSC_VERSION_MINOR << " . " << PETSC_VERSION_SUBMINOR << " \n\n " ;
267288
268- cout << " Compiled at: " << __DATE__ << " at " << __TIME__ << std::endl << std::endl;
289+ cout << " Compiled at: " << __DATE__ << " at " << __TIME__ << " \n "
290+ << std::endl;
269291}
270292
271293void CLI::help_print (const po::options_description& flags) {
@@ -463,7 +485,8 @@ static void strcopy_to_fortran(const std::string& src, char* dest) {
463485 * @param[out] uuid UUID buffer
464486 * @param[out] jobname Jobname buffer
465487 * @param[out] restart Restart increment (only relevant for grid solver)
466- * @param[out] stat Status flag: always returns 0 here, failure will be implicit from buffer error
488+ * @param[out] stat Status flag: always returns 0 here, failure will be implicit from
489+ * buffer error
467490 */
468491void C_CLI_getParsedArgs (CLI * cli,
469492 char geom[],
0 commit comments