[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master f519b8f: Query: new --dry-run option to just p
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master f519b8f: Query: new --dry-run option to just print command, not run it |
Date: |
Fri, 22 Jan 2021 17:59:28 -0500 (EST) |
branch: master
commit f519b8fa94e9b8fa689248c4abbe777cbee01979
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Query: new --dry-run option to just print command, not run it
Until now, the only way a user could check the download command was to
actually run it and then cancel the run to see what is actually being
run. This is very annoying!
With this commit, Query now has a '--dry-run' option precisely for this
purpose. With this option, it will just print the command that it would run
otherwise and abort.
---
bin/query/args.h | 13 +++++++++++++
bin/query/main.h | 1 +
bin/query/query.c | 5 +++--
bin/query/tap.c | 25 +++++++++++++++----------
bin/query/ui.h | 1 +
doc/gnuastro.texi | 5 +++++
6 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/bin/query/args.h b/bin/query/args.h
index 58df1f9..c8d2e2d 100644
--- a/bin/query/args.h
+++ b/bin/query/args.h
@@ -90,6 +90,19 @@ struct argp_option program_options[] =
GAL_OPTIONS_NOT_MANDATORY,
GAL_OPTIONS_NOT_SET
},
+ {
+ "dry-run",
+ UI_KEY_DRYRUN,
+ 0,
+ 0,
+ "Only print the download command, don't run it.",
+ GAL_OPTIONS_GROUP_OUTPUT,
+ &p->dryrun,
+ GAL_OPTIONS_NO_ARG_TYPE,
+ GAL_OPTIONS_RANGE_0_OR_1,
+ GAL_OPTIONS_NOT_MANDATORY,
+ GAL_OPTIONS_NOT_SET
+ },
diff --git a/bin/query/main.h b/bin/query/main.h
index 97f0aa4..377d41c 100644
--- a/bin/query/main.h
+++ b/bin/query/main.h
@@ -46,6 +46,7 @@ struct queryparams
struct gal_options_common_params cp; /* Common parameters. */
uint8_t keeprawdownload; /* Keep raw downloaded file. */
uint8_t information; /* Print information on database. */
+ uint8_t dryrun; /* Only print command, don't run it. */
char *limitinfo; /* Limit retried dataset information. */
int database; /* ID of database to use. */
char *datasetstr; /* ID of dataset in database to use. */
diff --git a/bin/query/query.c b/bin/query/query.c
index 12d0648..b8289b5 100644
--- a/bin/query/query.c
+++ b/bin/query/query.c
@@ -364,10 +364,11 @@ query(struct queryparams *p)
/* Make sure that the result is a readable FITS file, otherwise, abort
with an error. */
- query_check_download(p);
+ if(p->dryrun==0)
+ query_check_download(p);
/* Let the user know that things went well. */
- if(p->cp.quiet==0)
+ if(p->dryrun==0 && p->cp.quiet==0)
{
if(p->information==0)
printf("\nQuery resulted in %zu rows and %zu columns.\n",
diff --git a/bin/query/tap.c b/bin/query/tap.c
index 064e25a..f934644 100644
--- a/bin/query/tap.c
+++ b/bin/query/tap.c
@@ -409,11 +409,12 @@ tap_download(struct queryparams *p)
__func__);
/* Print the calling command for the user to know. */
- if(p->cp.quiet==0)
+ if(p->dryrun==1 || p->cp.quiet==0)
{
- printf("\n");
- error(EXIT_SUCCESS, 0, "running: %s", command);
- printf("\nDownload status:\n");
+ if(p->dryrun==0) printf("\n");
+ error(EXIT_SUCCESS, 0, "%s: %s",
+ p->dryrun ? "would run" : "running", command);
+ if(p->dryrun==0) printf("\nDownload status:\n");
}
/* Run the command: if it succeeds ('system' returns zero), then stop
@@ -421,13 +422,17 @@ tap_download(struct queryparams *p)
URL or not. If its the last one ('url->next' is NULL), then exit
with a failure, otherwise, just let the user know that this
download failed, but continue with the next URLs. */
- if(system(command)==EXIT_SUCCESS) break;
+ if(p->dryrun) break;
else
- error(url->next ? EXIT_SUCCESS : EXIT_FAILURE, 0,
- "the query download command %sfailed%s\n",
- p->cp.quiet==0 ? "printed above " : "",
- p->cp.quiet==0 ? "" : " (the command can be printed "
- "if you don't use the option '--quiet', or '-q')");
+ {
+ if(system(command)==EXIT_SUCCESS) break;
+ else
+ error(url->next ? EXIT_SUCCESS : EXIT_FAILURE, 0,
+ "the query download command %sfailed%s\n",
+ p->cp.quiet==0 ? "printed above " : "",
+ p->cp.quiet==0 ? "" : " (the command can be printed "
+ "if you don't use the option '--quiet', or '-q')");
+ }
}
/* Keep the executed command (to put in the final file's meta-data). */
diff --git a/bin/query/ui.h b/bin/query/ui.h
index 4f960f2..f72a6a4 100644
--- a/bin/query/ui.h
+++ b/bin/query/ui.h
@@ -67,6 +67,7 @@ enum option_keys_enum
automatically). */
UI_KEY_CCOL = 1000,
UI_KEY_SORT,
+ UI_KEY_DRYRUN,
};
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 65c95b7..e7e5856 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -10651,6 +10651,11 @@ Unfotunately many databases don't write the input
queries into their generated t
@table @option
+@item --dry-run
+Only print the final download command to contact the server, don't actually
run it.
+This option is good when you want to check the finally constructed query or
download options given to the download program.
+You may also want to use the constructed command as a base to do further
customizations on it and run it yourself.
+
@item -k
@itemx --keeprawdownload
Don't delete the raw downloaded file from the database.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master f519b8f: Query: new --dry-run option to just print command, not run it,
Mohammad Akhlaghi <=