Command Line Arguments: all errors now print to the stderr

This was done by some callbacks but not all.
Only use the stdout for status & information.
This commit is contained in:
Campbell Barton 2023-01-25 12:20:48 +11:00
parent 6c310acccc
commit 7416021bf7
1 changed files with 82 additions and 74 deletions

View File

@ -792,7 +792,7 @@ static int arg_handle_log_level_set(int argc, const char **argv, void *UNUSED(da
if (argc > 1) {
const char *err_msg = NULL;
if (!parse_int_clamp(argv[1], NULL, -1, INT_MAX, &G.log.level, &err_msg)) {
printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
fprintf(stderr, "\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
}
else {
if (G.log.level == -1) {
@ -802,7 +802,7 @@ static int arg_handle_log_level_set(int argc, const char **argv, void *UNUSED(da
}
return 1;
}
printf("\nError: '%s' no args given.\n", arg_id);
fprintf(stderr, "\nError: '%s' no args given.\n", arg_id);
return 0;
}
@ -852,7 +852,7 @@ static int arg_handle_log_file_set(int argc, const char **argv, void *UNUSED(dat
FILE *fp = BLI_fopen(argv[1], "w");
if (fp == NULL) {
const char *err_msg = errno ? strerror(errno) : "unknown";
printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
fprintf(stderr, "\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
}
else {
if (UNLIKELY(G.log.file != NULL)) {
@ -863,7 +863,7 @@ static int arg_handle_log_file_set(int argc, const char **argv, void *UNUSED(dat
}
return 1;
}
printf("\nError: '%s' no args given.\n", arg_id);
fprintf(stderr, "\nError: '%s' no args given.\n", arg_id);
return 0;
}
@ -906,7 +906,7 @@ static int arg_handle_log_set(int argc, const char **argv, void *UNUSED(data))
}
return 1;
}
printf("\nError: '%s' no args given.\n", arg_id);
fprintf(stderr, "\nError: '%s' no args given.\n", arg_id);
return 0;
}
@ -1091,7 +1091,7 @@ static int arg_handle_debug_value_set(int argc, const char **argv, void *UNUSED(
const char *err_msg = NULL;
int value;
if (!parse_int(argv[1], NULL, &value, &err_msg)) {
printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
fprintf(stderr, "\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
return 1;
}
@ -1099,7 +1099,7 @@ static int arg_handle_debug_value_set(int argc, const char **argv, void *UNUSED(
return 1;
}
printf("\nError: you must specify debug value to set.\n");
fprintf(stderr, "\nError: you must specify debug value to set.\n");
return 0;
}
@ -1188,7 +1188,7 @@ static int arg_handle_app_template(int argc, const char **argv, void *UNUSED(dat
WM_init_state_app_template_set(app_template);
return 1;
}
printf("\nError: App template must follow '--app-template'.\n");
fprintf(stderr, "\nError: App template must follow '--app-template'.\n");
return 0;
}
@ -1234,7 +1234,7 @@ static int arg_handle_env_system_set(int argc, const char **argv, void *UNUSED(d
const char *ch_src = argv[0] + 5; /* skip --env */
if (argc < 2) {
printf("%s requires one argument\n", argv[0]);
fprintf(stderr, "%s requires one argument\n", argv[0]);
exit(1);
}
@ -1303,7 +1303,7 @@ static int arg_handle_window_geometry(int argc, const char **argv, void *UNUSED(
for (i = 0; i < 4; i++) {
const char *err_msg = NULL;
if (!parse_int(argv[i + 1], NULL, &params[i], &err_msg)) {
printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
fprintf(stderr, "\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
exit(1);
}
}
@ -1449,11 +1449,11 @@ static int arg_handle_output_set(int argc, const char **argv, void *data)
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
}
else {
printf("\nError: no blend loaded. cannot use '-o / --render-output'.\n");
fprintf(stderr, "\nError: no blend loaded. cannot use '-o / --render-output'.\n");
}
return 1;
}
printf("\nError: you must specify a path after '-o / --render-output'.\n");
fprintf(stderr, "\nError: you must specify a path after '-o / --render-output'.\n");
return 0;
}
@ -1481,20 +1481,20 @@ static int arg_handle_engine_set(int argc, const char **argv, void *data)
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
}
else {
printf("\nError: engine not found '%s'\n", argv[1]);
fprintf(stderr, "\nError: engine not found '%s'\n", argv[1]);
exit(1);
}
}
else {
printf(
"\nError: no blend loaded. "
"order the arguments so '-E / --engine' is after a blend is loaded.\n");
fprintf(stderr,
"\nError: no blend loaded. "
"order the arguments so '-E / --engine' is after a blend is loaded.\n");
}
}
return 1;
}
printf("\nEngine not specified, give 'help' for a list of available engines.\n");
fprintf(stderr, "\nEngine not specified, give 'help' for a list of available engines.\n");
return 0;
}
@ -1516,9 +1516,9 @@ static int arg_handle_image_type_set(int argc, const char **argv, void *data)
const char imtype_new = BKE_imtype_from_arg(imtype);
if (imtype_new == R_IMF_IMTYPE_INVALID) {
printf(
"\nError: Format from '-F / --render-format' not known or not compiled in this "
"release.\n");
fprintf(stderr,
"\nError: Format from '-F / --render-format' not known or not compiled in this "
"release.\n");
}
else {
scene->r.im_format.imtype = imtype_new;
@ -1526,13 +1526,13 @@ static int arg_handle_image_type_set(int argc, const char **argv, void *data)
}
}
else {
printf(
"\nError: no blend loaded. "
"order the arguments so '-F / --render-format' is after the blend is loaded.\n");
fprintf(stderr,
"\nError: no blend loaded. "
"order the arguments so '-F / --render-format' is after the blend is loaded.\n");
}
return 1;
}
printf("\nError: you must specify a format after '-F / --render-format'.\n");
fprintf(stderr, "\nError: you must specify a format after '-F / --render-format'.\n");
return 0;
}
@ -1548,19 +1548,24 @@ static int arg_handle_threads_set(int argc, const char **argv, void *UNUSED(data
const char *err_msg = NULL;
int threads;
if (!parse_int_strict_range(argv[1], NULL, min, max, &threads, &err_msg)) {
printf("\nError: %s '%s %s', expected number in [%d..%d].\n",
err_msg,
arg_id,
argv[1],
min,
max);
fprintf(stderr,
"\nError: %s '%s %s', expected number in [%d..%d].\n",
err_msg,
arg_id,
argv[1],
min,
max);
return 1;
}
BLI_system_num_threads_override_set(threads);
return 1;
}
printf("\nError: you must specify a number of threads in [%d..%d] '%s'.\n", min, max, arg_id);
fprintf(stderr,
"\nError: you must specify a number of threads in [%d..%d] '%s'.\n",
min,
max,
arg_id);
return 0;
}
@ -1574,7 +1579,7 @@ static int arg_handle_verbosity_set(int argc, const char **argv, void *UNUSED(da
const char *err_msg = NULL;
int level;
if (!parse_int(argv[1], NULL, &level, &err_msg)) {
printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
fprintf(stderr, "\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
}
# ifdef WITH_LIBMV
@ -1587,7 +1592,7 @@ static int arg_handle_verbosity_set(int argc, const char **argv, void *UNUSED(da
return 1;
}
printf("\nError: you must specify a verbosity level.\n");
fprintf(stderr, "\nError: you must specify a verbosity level.\n");
return 0;
}
@ -1609,17 +1614,18 @@ static int arg_handle_extension_set(int argc, const char **argv, void *data)
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
}
else {
printf("\nError: Use '-x 1 / -x 0' To set the extension option or '--use-extension'\n");
fprintf(stderr,
"\nError: Use '-x 1 / -x 0' To set the extension option or '--use-extension'\n");
}
}
else {
printf(
"\nError: no blend loaded. "
"order the arguments so '-o ' is after '-x '.\n");
fprintf(stderr,
"\nError: no blend loaded. "
"order the arguments so '-o ' is after '-x '.\n");
}
return 1;
}
printf("\nError: you must specify a path after '- '.\n");
fprintf(stderr, "\nError: you must specify a path after '- '.\n");
return 0;
}
@ -1652,7 +1658,7 @@ static int arg_handle_render_frame(int argc, const char **argv, void *data)
MAXFRAME,
&frames_range_len,
&err_msg)) == NULL) {
printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
fprintf(stderr, "\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
return 1;
}
@ -1663,7 +1669,7 @@ static int arg_handle_render_frame(int argc, const char **argv, void *data)
/* We could pass in frame ranges,
* but prefer having exact behavior as passing in multiple frames */
if ((frame_range_arr[i][0] <= frame_range_arr[i][1]) == 0) {
printf("\nWarning: negative range ignored '%s %s'.\n", arg_id, argv[1]);
fprintf(stderr, "\nWarning: negative range ignored '%s %s'.\n", arg_id, argv[1]);
}
for (int frame = frame_range_arr[i][0]; frame <= frame_range_arr[i][1]; frame++) {
@ -1675,10 +1681,10 @@ static int arg_handle_render_frame(int argc, const char **argv, void *data)
MEM_freeN(frame_range_arr);
return 1;
}
printf("\nError: frame number must follow '%s'.\n", arg_id);
fprintf(stderr, "\nError: frame number must follow '%s'.\n", arg_id);
return 0;
}
printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
fprintf(stderr, "\nError: no blend loaded. cannot use '%s'.\n", arg_id);
return 0;
}
@ -1700,7 +1706,7 @@ static int arg_handle_render_animation(int UNUSED(argc), const char **UNUSED(arg
BKE_reports_clear(&reports);
}
else {
printf("\nError: no blend loaded. cannot use '-a'.\n");
fprintf(stderr, "\nError: no blend loaded. cannot use '-a'.\n");
}
return 0;
}
@ -1728,7 +1734,7 @@ static int arg_handle_scene_set(int argc, const char **argv, void *data)
}
return 1;
}
printf("\nError: Scene name must follow '-S / --scene'.\n");
fprintf(stderr, "\nError: Scene name must follow '-S / --scene'.\n");
return 0;
}
@ -1751,17 +1757,17 @@ static int arg_handle_frame_start_set(int argc, const char **argv, void *data)
MAXFRAME,
&scene->r.sfra,
&err_msg)) {
printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
fprintf(stderr, "\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
}
else {
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
}
return 1;
}
printf("\nError: frame number must follow '%s'.\n", arg_id);
fprintf(stderr, "\nError: frame number must follow '%s'.\n", arg_id);
return 0;
}
printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
fprintf(stderr, "\nError: no blend loaded. cannot use '%s'.\n", arg_id);
return 0;
}
@ -1784,17 +1790,17 @@ static int arg_handle_frame_end_set(int argc, const char **argv, void *data)
MAXFRAME,
&scene->r.efra,
&err_msg)) {
printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
fprintf(stderr, "\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
}
else {
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
}
return 1;
}
printf("\nError: frame number must follow '%s'.\n", arg_id);
fprintf(stderr, "\nError: frame number must follow '%s'.\n", arg_id);
return 0;
}
printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
fprintf(stderr, "\nError: no blend loaded. cannot use '%s'.\n", arg_id);
return 0;
}
@ -1810,17 +1816,17 @@ static int arg_handle_frame_skip_set(int argc, const char **argv, void *data)
if (argc > 1) {
const char *err_msg = NULL;
if (!parse_int_clamp(argv[1], NULL, 1, MAXFRAME, &scene->r.frame_step, &err_msg)) {
printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
fprintf(stderr, "\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
}
else {
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
}
return 1;
}
printf("\nError: number of frames to step must follow '%s'.\n", arg_id);
fprintf(stderr, "\nError: number of frames to step must follow '%s'.\n", arg_id);
return 0;
}
printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
fprintf(stderr, "\nError: no blend loaded. cannot use '%s'.\n", arg_id);
return 0;
}
@ -1842,18 +1848,18 @@ static int arg_handle_python_file_run(int argc, const char **argv, void *data)
bool ok;
BPY_CTX_SETUP(ok = BPY_run_filepath(C, filepath, NULL));
if (!ok && app_state.exit_code_on_error.python) {
printf("\nError: script failed, file: '%s', exiting.\n", argv[1]);
fprintf(stderr, "\nError: script failed, file: '%s', exiting.\n", argv[1]);
BPY_python_end();
exit(app_state.exit_code_on_error.python);
}
return 1;
}
printf("\nError: you must specify a filepath after '%s'.\n", argv[0]);
fprintf(stderr, "\nError: you must specify a filepath after '%s'.\n", argv[0]);
return 0;
# else
UNUSED_VARS(argc, argv, data);
printf("This Blender was built without Python support\n");
fprintf(stderr, "This Blender was built without Python support\n");
return 0;
# endif /* WITH_PYTHON */
}
@ -1877,24 +1883,24 @@ static int arg_handle_python_text_run(int argc, const char **argv, void *data)
BPY_CTX_SETUP(ok = BPY_run_text(C, text, NULL, false));
}
else {
printf("\nError: text block not found %s.\n", argv[1]);
fprintf(stderr, "\nError: text block not found %s.\n", argv[1]);
ok = false;
}
if (!ok && app_state.exit_code_on_error.python) {
printf("\nError: script failed, text: '%s', exiting.\n", argv[1]);
fprintf(stderr, "\nError: script failed, text: '%s', exiting.\n", argv[1]);
BPY_python_end();
exit(app_state.exit_code_on_error.python);
}
return 1;
}
printf("\nError: you must specify a text block after '%s'.\n", argv[0]);
fprintf(stderr, "\nError: you must specify a text block after '%s'.\n", argv[0]);
return 0;
# else
UNUSED_VARS(argc, argv, data);
printf("This Blender was built without Python support\n");
fprintf(stderr, "This Blender was built without Python support\n");
return 0;
# endif /* WITH_PYTHON */
}
@ -1912,18 +1918,18 @@ static int arg_handle_python_expr_run(int argc, const char **argv, void *data)
bool ok;
BPY_CTX_SETUP(ok = BPY_run_string_exec(C, NULL, argv[1]));
if (!ok && app_state.exit_code_on_error.python) {
printf("\nError: script failed, expr: '%s', exiting.\n", argv[1]);
fprintf(stderr, "\nError: script failed, expr: '%s', exiting.\n", argv[1]);
BPY_python_end();
exit(app_state.exit_code_on_error.python);
}
return 1;
}
printf("\nError: you must specify a Python expression after '%s'.\n", argv[0]);
fprintf(stderr, "\nError: you must specify a Python expression after '%s'.\n", argv[0]);
return 0;
# else
UNUSED_VARS(argc, argv, data);
printf("This Blender was built without Python support\n");
fprintf(stderr, "This Blender was built without Python support\n");
return 0;
# endif /* WITH_PYTHON */
}
@ -1941,7 +1947,7 @@ static int arg_handle_python_console_run(int UNUSED(argc), const char **argv, vo
return 0;
# else
UNUSED_VARS(argv, data);
printf("This Blender was built without python support\n");
fprintf(stderr, "This Blender was built without python support\n");
return 0;
# endif /* WITH_PYTHON */
}
@ -1958,19 +1964,20 @@ static int arg_handle_python_exit_code_set(int argc, const char **argv, void *UN
const int min = 0, max = 255;
int exit_code;
if (!parse_int_strict_range(argv[1], NULL, min, max, &exit_code, &err_msg)) {
printf("\nError: %s '%s %s', expected number in [%d..%d].\n",
err_msg,
arg_id,
argv[1],
min,
max);
fprintf(stderr,
"\nError: %s '%s %s', expected number in [%d..%d].\n",
err_msg,
arg_id,
argv[1],
min,
max);
return 1;
}
app_state.exit_code_on_error.python = (uchar)exit_code;
return 1;
}
printf("\nError: you must specify an exit code number '%s'.\n", arg_id);
fprintf(stderr, "\nError: you must specify an exit code number '%s'.\n", arg_id);
return 0;
}
@ -2014,7 +2021,7 @@ static int arg_handle_addons_set(int argc, const char **argv, void *data)
# endif /* WITH_PYTHON */
return 1;
}
printf("\nError: you must specify a comma separated list after '--addons'.\n");
fprintf(stderr, "\nError: you must specify a comma separated list after '--addons'.\n");
return 0;
}
@ -2068,7 +2075,8 @@ static int arg_handle_load_file(int UNUSED(argc), const char **argv, void *data)
printf("... opened default scene instead; saving will write to: %s\n", filepath);
}
else {
printf(
fprintf(
stderr,
"Error: argument has no '.blend' file extension, not using as new file, exiting! %s\n",
filepath);
G.is_break = true;
@ -2085,7 +2093,7 @@ static const char arg_handle_load_last_file_doc[] =
static int arg_handle_load_last_file(int UNUSED(argc), const char **UNUSED(argv), void *data)
{
if (BLI_listbase_is_empty(&G.recent_files)) {
printf("Warning: no recent files known, opening default startup file instead.\n");
fprintf(stderr, "Warning: no recent files known, opening default startup file instead.\n");
return -1;
}