Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions examples/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct SDCliParams {
if (mode_found == -1) {
LOG_ERROR("error: invalid mode %s, must be one of [%s]\n",
mode_c_str, SD_ALL_MODES_STR);
exit(1);
return -1;
}
mode = (SDMode)mode_found;
}
Expand Down Expand Up @@ -209,19 +209,23 @@ void print_usage(int argc, const char* argv[], const std::vector<ArgOptions>& op
options_list[2].print();
}

void parse_args(int argc, const char** argv, SDCliParams& cli_params, SDContextParams& ctx_params, SDGenerationParams& gen_params) {
int parse_args(int argc, const char** argv, SDCliParams& cli_params, SDContextParams& ctx_params, SDGenerationParams& gen_params, bool& proceed) {
std::vector<ArgOptions> options_vec = {cli_params.get_options(), ctx_params.get_options(), gen_params.get_options()};

proceed = true;

if (!parse_options(argc, argv, options_vec)) {
print_usage(argc, argv, options_vec);
exit(cli_params.normal_exit ? 0 : 1);
proceed = false;
return cli_params.normal_exit ? 0 : 1;
}

if (!cli_params.process_and_check() ||
!ctx_params.process_and_check(cli_params.mode) ||
!gen_params.process_and_check(cli_params.mode, ctx_params.lora_model_dir)) {
print_usage(argc, argv, options_vec);
exit(1);
proceed = false;
return 1;
}
}

Expand Down Expand Up @@ -469,7 +473,9 @@ int main(int argc, const char* argv[]) {
SDContextParams ctx_params;
SDGenerationParams gen_params;

parse_args(argc, argv, cli_params, ctx_params, gen_params);
bool proceed;
int parsing_exit_code = parse_args(argc, argv, cli_params, ctx_params, gen_params, proceed);
if (proceed) {
if (gen_params.video_frames > 4) {
size_t last_dot_pos = cli_params.preview_path.find_last_of(".");
std::string base_path = cli_params.preview_path;
Expand Down Expand Up @@ -813,6 +819,6 @@ int main(int argc, const char* argv[]) {
free(results);

release_all_resources();

return 0;
}
return parsing_exit_code;
}
4 changes: 4 additions & 0 deletions examples/common/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ static bool parse_options(int argc, const char** argv, const std::vector<ArgOpti
break;
}

if (arg == "-h" || arg == "--help") {
return false;
}

if (invalid_arg) {
LOG_ERROR("error: invalid parameter for argument: %s", arg.c_str());
return false;
Expand Down
Loading