]> wimlib.net Git - wimlib/blobdiff - programs/imagex.c
imagex_extract(): Cleanups
[wimlib] / programs / imagex.c
index 407967fa784d6363907793f7e3eb5cc05e788303..ed0a977625ed136859fb3e38c52123c9d78b2cdd 100644 (file)
@@ -170,16 +170,25 @@ IMAGEX_PROGNAME" unmount DIRECTORY [--commit] [--check] [--rebuild]\n"
 [UPDATE] =
 T(
 IMAGEX_PROGNAME" update WIMFILE IMAGE [--check] [--rebuild]\n"
-"                      [--threads=NUM_THREADS] [DEFAULT_ADD_OPTIONS]\n"
-"                      [DEFAULT_DELETE_OPTIONS] [< CMDFILE]\n"
-"               ... where each CMD is:\n"
-"               add [--unix-data] [--no-acls] [--strict-acls] [--dereference]\n"
-"                   [--verbose] FILE_OR_DIRECTORY DEST_WIM_PATH\n"
-"               delete [--force] [--recursive] WIM_PATH\n"
-"               rename SRC_PATH_IN_WIM DEST_PATH_IN_WIM\n"
+"                       [--threads=NUM_THREADS] [DEFAULT_ADD_OPTIONS]\n"
+"                       [DEFAULT_DELETE_OPTIONS] < CMDFILE\n"
 ),
 };
 
+
+static void
+recommend_man_page(const tchar *cmd_name)
+{
+#ifdef __WIN32__
+       tprintf(T("See "IMAGEX_PROGNAME"-%"TS".pdf in the "
+                 "doc directory for more details.\n"),
+               cmd_name);
+#else
+       tprintf(T("Try `man "IMAGEX_PROGNAME"-%"TS"' "
+                 "for more details.\n"), cmd_name);
+#endif
+}
+
 enum {
        IMAGEX_ALLOW_OTHER_OPTION,
        IMAGEX_BOOT_OPTION,
@@ -2106,18 +2115,19 @@ free_extract_commands(struct wimlib_extract_command *cmds, size_t num_cmds,
 }
 
 static struct wimlib_extract_command *
-prepare_extract_commands(tchar **argv, int argc, int extract_flags,
-                        tchar *dest_dir, size_t *num_cmds_ret)
+prepare_extract_commands(tchar **paths, unsigned num_paths,
+                        int extract_flags, tchar *dest_dir,
+                        size_t *num_cmds_ret)
 {
        struct wimlib_extract_command *cmds;
        size_t num_cmds;
        tchar *emptystr = T("");
 
-       if (argc == 0) {
-               argc = 1;
-               argv = &emptystr;
+       if (num_paths == 0) {
+               num_paths = 1;
+               paths = &emptystr;
        }
-       num_cmds = argc;
+       num_cmds = num_paths;
        cmds = calloc(num_cmds, sizeof(cmds[0]));
        if (!cmds) {
                imagex_error(T("Out of memory!"));
@@ -2126,18 +2136,18 @@ prepare_extract_commands(tchar **argv, int argc, int extract_flags,
 
        for (size_t i = 0; i < num_cmds; i++) {
                cmds[i].extract_flags = extract_flags;
-               cmds[i].wim_source_path = argv[i];
-               if (is_root_wim_path(argv[i])) {
+               cmds[i].wim_source_path = paths[i];
+               if (is_root_wim_path(paths[i])) {
                        cmds[i].fs_dest_path = dest_dir;
                } else {
-                       size_t len = tstrlen(dest_dir) + 1 + tstrlen(argv[i]);
+                       size_t len = tstrlen(dest_dir) + 1 + tstrlen(paths[i]);
                        cmds[i].fs_dest_path = malloc((len + 1) * sizeof(tchar));
                        if (!cmds[i].fs_dest_path) {
                                free_extract_commands(cmds, num_cmds, dest_dir);
                                return NULL;
                        }
                        tsprintf(cmds[i].fs_dest_path, T("%"TS"/%"TS), dest_dir,
-                                tbasename(argv[i]));
+                                tbasename(paths[i]));
                }
        }
        *num_cmds_ret = num_cmds;
@@ -2193,19 +2203,15 @@ imagex_extract(int argc, tchar **argv)
                        imagex_be_quiet = true;
                        break;
                default:
-                       usage(EXTRACT);
-                       ret = -1;
-                       goto out;
+                       goto out_usage;
                }
        }
        argc -= optind;
        argv += optind;
 
-       if (argc < 2) {
-               usage(EXTRACT);
-               ret = -1;
-               goto out;
-       }
+       if (argc < 2)
+               goto out_usage;
+
        wimfile = argv[0];
        image_num_or_name = argv[1];
 
@@ -2267,6 +2273,10 @@ out_free_cmds:
        free_extract_commands(cmds, num_cmds, dest_dir);
 out:
        return ret;
+out_usage:
+       usage(EXTRACT);
+       ret = -1;
+       goto out;
 }
 
 /* Prints information about a WIM file; also can mark an image as bootable,
@@ -2989,8 +2999,10 @@ imagex_update(int argc, tchar **argv)
        }
 
        /* Read update commands from standard input */
-       if (isatty(STDIN_FILENO))
+       if (isatty(STDIN_FILENO)) {
                tputs(T("Reading update commands from standard input..."));
+               recommend_man_page(T("update"));
+       }
        cmd_file_contents = stdin_get_text_contents(&cmd_file_nchars);
        if (!cmd_file_contents) {
                ret = -1;
@@ -3134,8 +3146,8 @@ usage(int cmd_type)
        tprintf(T("Usage:\n%"TS), usage_strings[cmd_type]);
        for_imagex_command(cmd) {
                if (cmd->cmd == cmd_type) {
-                       tprintf(T("\nTry `man "IMAGEX_PROGNAME"-%"TS"' "
-                                 "for more details.\n"), cmd->name);
+                       tputc(T('\n'), stdout);
+                       recommend_man_page(cmd->name);
                }
        }
 }