Add noconfirm flag

This commit is contained in:
Imbus 2026-02-07 17:24:31 +01:00
parent 13e27bbcc1
commit c67c68615a

View file

@ -57,11 +57,12 @@ const char help[] =
" writeimg [-v] -d <device> <file.img>\n" " writeimg [-v] -d <device> <file.img>\n"
"\n" "\n"
"Args:\n" "Args:\n"
" <file.img> Binary image file\n" " <file.img> Binary image file\n"
" -v Verify only\n" " -v Verify only\n"
" -d device Target block device\n" " -d device Target block device\n"
" -h, --help Print this help message\n" " -h, --help Print this help message\n"
" -V, --version Print version\n" " -n, --noconfirm Do not ask for premission\n"
" -V, --version Print version\n"
"\0"; "\0";
// clang-format on // clang-format on
@ -209,12 +210,14 @@ int main(int argc, char *argv[]) {
signal(SIGHUP, int_handler); signal(SIGHUP, int_handler);
signal(SIGTERM, int_handler); signal(SIGTERM, int_handler);
int ask_permission = 1;
int c = {0}; int c = {0};
while ((c = getopt_long(argc, argv, "vd:hV", longopts, 0)) != -1) { while ((c = getopt_long(argc, argv, "vd:hnV", longopts, 0)) != -1) {
switch (c) { switch (c) {
case 'v': ++wjob.verify_only; continue; case 'v': ++wjob.verify_only; continue;
case 'd': wjob.dev_name = optarg; continue; case 'd': wjob.dev_name = optarg; continue;
case 'h': break; case 'h': break;
case 'n': --ask_permission; continue;
case 'V': exit(EXIT_SUCCESS); case 'V': exit(EXIT_SUCCESS);
} }
printf("%s\n", help); printf("%s\n", help);