Add a '--showcmd' option for dumping a job file

It effectively shows what the equivelant command line string would be.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/init.c b/init.c
index 50c4760..0151c9b 100644
--- a/init.c
+++ b/init.c
@@ -23,6 +23,7 @@
 
 static char **ini_file;
 static int max_jobs = MAX_JOBS;
+static int dump_cmdline;
 
 struct thread_data def_thread;
 struct thread_data *threads = NULL;
@@ -86,6 +87,11 @@
 		.val		= 'c',
 	},
 	{
+		.name		= "showcmd",
+		.has_arg	= no_argument,
+		.val		= 's'
+	},
+	{
 		.name		= NULL,
 	},
 };
@@ -381,6 +387,14 @@
 	if (td == &def_thread)
 		return 0;
 
+	/*
+	 * if we are just dumping the output command line, don't add the job
+	 */
+	if (dump_cmdline) {
+		put_job(td);
+		return 0;
+	}
+
 	engine = get_engine_name(td->o.ioengine);
 	td->io_ops = load_ioengine(td, engine);
 	if (!td->io_ops) {
@@ -560,6 +574,12 @@
 
 		name[strlen(name) - 1] = '\0';
 
+		if (dump_cmdline) {
+			log_info("fio ");
+			if (!global)
+				log_info("--name=%s ", name);
+		}
+
 		td = get_new_job(global, &def_thread);
 		if (!td) {
 			ret = 1;
@@ -594,6 +614,8 @@
 			 * easier on the user.
 			 */
 			ret |= fio_option_parse(td, p);
+			if (!ret && dump_cmdline)
+				log_info("--%s ", p);
 		}
 
 		if (!ret) {
@@ -605,6 +627,9 @@
 		}
 	} while (!ret);
 
+	if (dump_cmdline)
+		log_info("\n");
+
 	free(string);
 	free(name);
 	fclose(f);
@@ -696,6 +721,7 @@
 	printf("\t--version\tPrint version info and exit\n");
 	printf("\t--help\t\tPrint this page\n");
 	printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
+	printf("\t--showcmd\tTurn a job file into command line options\n");
 }
 
 static int parse_cmd_line(int argc, char *argv[])
@@ -730,6 +756,9 @@
 			exit(0);
 		case 'c':
 			exit(fio_show_option_help(optarg));
+		case 's':
+			dump_cmdline = 1;
+			break;
 		case 'v':
 			printf("%s\n", fio_version_string);
 			exit(0);
@@ -812,6 +841,9 @@
 	options_mem_free(&def_thread);
 
 	if (!thread_number) {
+		if (dump_cmdline)
+			return 0;
+
 		log_err("No jobs defined(s)\n");
 		return 1;
 	}