curl/src
Daniel Stenberg 2e160c9c65
tool: add "variable" support
Add support for command line variables. Set variables with --variable
name=content or --variable name@file (where "file" can be stdin if set
to a single dash (-)).

Variable content is expanded in option parameters using "{{name}}"
(without the quotes) if the option name is prefixed with
"--expand-". This gets the contents of the variable "name" inserted, or
a blank if the name does not exist as a variable. Insert "{{" verbatim
in the string by prefixing it with a backslash, like "\\{{".

Import an environment variable with --variable %name. It makes curl exit
with an error if the environment variable is not set. It can also rather
get a default value if the variable does not exist, using =content or
@file like shown above.

Example: get the USER environment variable into the URL:

 --variable %USER
 --expand-url = "https://example.com/api/{{USER}}/method"

When expanding variables, curl supports a set of functions that can make
the variable contents more convenient to use. It can trim leading and
trailing white space with "trim", output the contents as a JSON quoted
string with "json", URL encode it with "url" and base 64 encode it with
"b64". To apply functions to a variable expansion, add them colon
separated to the right side of the variable. They are then performed in
a left to right order.

Example: get the contents of a file called $HOME/.secret into a variable
called "fix". Make sure that the content is trimmed and percent-encoded
sent as POST data:

  --variable %HOME=/home/default
  --expand-variable fix@{{HOME}}/.secret
  --expand-data "{{fix:trim:url}}"
  https://example.com/

Documented. Many new test cases.

Co-brainstormed-by: Emanuele Torre
Assisted-by: Jat Satiro
Closes #11346
2023-07-31 11:51:34 +02:00
..
.gitignore copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
CMakeLists.txt tool: add "variable" support 2023-07-31 11:51:34 +02:00
curl.rc copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
Makefile.am nss: remove support for this TLS library 2023-07-29 23:44:28 +02:00
Makefile.inc tool: add "variable" support 2023-07-31 11:51:34 +02:00
Makefile.mk copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
mkhelp.pl src/mkhelp: strip off escape sequences 2023-07-23 23:30:51 +02:00
slist_wc.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
slist_wc.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_binmode.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_binmode.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_bname.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_bname.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_dbg.c tool: add curl command line option --trace-ids 2023-06-12 23:53:09 +02:00
tool_cb_dbg.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_hdr.c tool: remove exclamation marks from error/warning messages 2023-06-01 08:19:21 +02:00
tool_cb_hdr.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_prg.c tool: improve --stderr handling 2023-03-12 00:58:40 -05:00
tool_cb_prg.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_rea.c curl: count uploaded data to stop at the originally given size 2023-06-01 13:43:28 +02:00
tool_cb_rea.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_see.c tool: fix tool_seek_cb build when SIZEOF_CURL_OFF_T > SIZEOF_OFF_T 2023-07-19 15:36:41 +02:00
tool_cb_see.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_wrt.c tool: remove exclamation marks from error/warning messages 2023-06-01 08:19:21 +02:00
tool_cb_wrt.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cfgable.c haproxy: add --haproxy-clientip flag to spoof client IPs 2023-06-05 20:08:37 +02:00
tool_cfgable.h tool: add "variable" support 2023-07-31 11:51:34 +02:00
tool_dirhie.c tool: use errorf() for error output 2023-06-01 08:19:11 +02:00
tool_dirhie.h tool: use errorf() for error output 2023-06-01 08:19:11 +02:00
tool_doswin.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_doswin.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_easysrc.c tool: remove exclamation marks from error/warning messages 2023-06-01 08:19:21 +02:00
tool_easysrc.h tool_easysrc.h: correct easysrc_perform for CURL_DISABLE_LIBCURL_OPTION 2023-07-09 18:50:16 +02:00
tool_filetime.c tool: remove newlines from all helpf/notef/warnf/errorf calls 2023-06-01 08:18:21 +02:00
tool_filetime.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_findfile.c cmake: add support for "unity" builds 2023-06-07 13:06:08 +00:00
tool_findfile.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_formparse.c tool: remove exclamation marks from error/warning messages 2023-06-01 08:19:21 +02:00
tool_formparse.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_getparam.c tool: add "variable" support 2023-07-31 11:51:34 +02:00
tool_getparam.h tool: add "variable" support 2023-07-31 11:51:34 +02:00
tool_getpass.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_getpass.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_help.c curl: output warning at --verbose output for debug-enabled version 2023-01-12 17:59:26 +01:00
tool_help.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_helpers.c tool: add "variable" support 2023-07-31 11:51:34 +02:00
tool_helpers.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_hugehelp.c.cvs copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_hugehelp.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_libinfo.c curl: return error when asked to use an unsupported HTTP version 2023-07-15 19:02:20 +02:00
tool_libinfo.h curl: return error when asked to use an unsupported HTTP version 2023-07-15 19:02:20 +02:00
tool_listhelp.c tool: add "variable" support 2023-07-31 11:51:34 +02:00
tool_main.c nss: remove support for this TLS library 2023-07-29 23:44:28 +02:00
tool_main.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_msgs.c tool: use errorf() for error output 2023-06-01 08:19:11 +02:00
tool_msgs.h tool: use errorf() for error output 2023-06-01 08:19:11 +02:00
tool_operate.c tool: add "variable" support 2023-07-31 11:51:34 +02:00
tool_operate.h curl: count uploaded data to stop at the originally given size 2023-06-01 13:43:28 +02:00
tool_operhlp.c checksrc: disallow spaces before labels 2023-05-18 20:45:04 +02:00
tool_operhlp.h tool_operate: Fix error codes on bad URL & OOM 2023-02-07 08:20:04 +01:00
tool_paramhlp.c tool: remove newlines from all helpf/notef/warnf/errorf calls 2023-06-01 08:18:21 +02:00
tool_paramhlp.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_parsecfg.c tool_parsecfg: accept line lengths up to 10M 2023-07-13 15:16:41 +02:00
tool_parsecfg.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_progress.c tool: improve --stderr handling 2023-03-12 00:58:40 -05:00
tool_progress.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_sdecls.h curl: count uploaded data to stop at the originally given size 2023-06-01 13:43:28 +02:00
tool_setopt.c tool: remove newlines from all helpf/notef/warnf/errorf calls 2023-06-01 08:18:21 +02:00
tool_setopt.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_setup.h cmake: add support for "unity" builds 2023-06-07 13:06:08 +00:00
tool_sleep.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_sleep.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_stderr.c tool: use errorf() for error output 2023-06-01 08:19:11 +02:00
tool_stderr.h tool: use errorf() for error output 2023-06-01 08:19:11 +02:00
tool_strdup.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_strdup.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_urlglob.c tool_urlglob: use curl_off_t instead of longs 2023-05-31 08:14:41 +02:00
tool_urlglob.h tool_urlglob: use curl_off_t instead of longs 2023-05-31 08:14:41 +02:00
tool_util.c cmake: add support for "unity" builds 2023-06-07 13:06:08 +00:00
tool_util.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_version.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_vms.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_vms.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_writeout.c lib: add CURLINFO_CONN_ID and CURLINFO_XFER_ID 2023-06-12 23:53:00 +02:00
tool_writeout.h lib: add CURLINFO_CONN_ID and CURLINFO_XFER_ID 2023-06-12 23:53:00 +02:00
tool_writeout_json.c tool: add "variable" support 2023-07-31 11:51:34 +02:00
tool_writeout_json.h tool: add "variable" support 2023-07-31 11:51:34 +02:00
tool_xattr.c checksrc: disallow spaces before labels 2023-05-18 20:45:04 +02:00
tool_xattr.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
var.c tool: add "variable" support 2023-07-31 11:51:34 +02:00
var.h tool: add "variable" support 2023-07-31 11:51:34 +02:00