mirror of
https://github.com/moparisthebest/curl
synced 2025-01-08 12:28:06 -05:00
tool_operate: Moved command line argument parsing into separate function
This commit is contained in:
parent
8034b08e0e
commit
c35d05aa62
@ -1847,3 +1847,47 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
|
|||||||
|
|
||||||
return PARAM_OK;
|
return PARAM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ParameterError parse_args(struct Configurable *config, int argc,
|
||||||
|
argv_item_t argv[])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
bool stillflags;
|
||||||
|
char *orig_opt;
|
||||||
|
ParameterError result = PARAM_OK;
|
||||||
|
|
||||||
|
for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
|
||||||
|
orig_opt = argv[i];
|
||||||
|
|
||||||
|
if(stillflags && ('-' == argv[i][0])) {
|
||||||
|
char *nextarg;
|
||||||
|
bool passarg;
|
||||||
|
char *flag = argv[i];
|
||||||
|
|
||||||
|
if(curlx_strequal("--", argv[i]))
|
||||||
|
/* This indicates the end of the flags and thus enables the
|
||||||
|
following (URL) argument to start with -. */
|
||||||
|
stillflags = FALSE;
|
||||||
|
else {
|
||||||
|
nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
|
||||||
|
|
||||||
|
result = getparameter(flag, nextarg, &passarg, config);
|
||||||
|
if(!result && passarg)
|
||||||
|
i++; /* we're supposed to skip this */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bool used;
|
||||||
|
|
||||||
|
/* Just add the URL please */
|
||||||
|
result = getparameter((char *)"--url", argv[i], &used, config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result && result != PARAM_HELP_REQUESTED) {
|
||||||
|
const char *reason = param2text(result);
|
||||||
|
helpf(config->errors, "option %s: %s\n", orig_opt, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* | (__| |_| | _ <| |___
|
* | (__| |_| | _ <| |___
|
||||||
* \___|\___/|_| \_\_____|
|
* \___|\___/|_| \_\_____|
|
||||||
*
|
*
|
||||||
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
*
|
*
|
||||||
* This software is licensed as described in the file COPYING, which
|
* This software is licensed as described in the file COPYING, which
|
||||||
* you should have received as part of this distribution. The terms
|
* you should have received as part of this distribution. The terms
|
||||||
@ -51,5 +51,8 @@ void parse_cert_parameter(const char *cert_parameter,
|
|||||||
char **passphrase);
|
char **passphrase);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ParameterError parse_args(struct Configurable *config, int argc,
|
||||||
|
argv_item_t argv[]);
|
||||||
|
|
||||||
#endif /* HEADER_CURL_TOOL_GETPARAM_H */
|
#endif /* HEADER_CURL_TOOL_GETPARAM_H */
|
||||||
|
|
||||||
|
@ -199,9 +199,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
|
|||||||
CURL *curl = NULL;
|
CURL *curl = NULL;
|
||||||
char *httpgetfields = NULL;
|
char *httpgetfields = NULL;
|
||||||
|
|
||||||
bool stillflags;
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int i;
|
|
||||||
unsigned long li;
|
unsigned long li;
|
||||||
|
|
||||||
bool orig_noprogress;
|
bool orig_noprogress;
|
||||||
@ -251,44 +249,15 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse options */
|
/* Parse the command line arguments */
|
||||||
for(i = 1, stillflags = TRUE; i < argc; i++) {
|
res = parse_args(config, argc, argv);
|
||||||
char *orig_opt = argv[i];
|
if(res) {
|
||||||
|
if(res != PARAM_HELP_REQUESTED)
|
||||||
|
res = CURLE_FAILED_INIT;
|
||||||
|
else
|
||||||
|
res = CURLE_OK;
|
||||||
|
|
||||||
if(stillflags &&
|
goto quit_curl;
|
||||||
('-' == argv[i][0])) {
|
|
||||||
char *nextarg;
|
|
||||||
bool passarg;
|
|
||||||
char *flag = argv[i];
|
|
||||||
|
|
||||||
if(curlx_strequal("--", argv[i]))
|
|
||||||
/* this indicates the end of the flags and thus enables the
|
|
||||||
following (URL) argument to start with -. */
|
|
||||||
stillflags = FALSE;
|
|
||||||
else {
|
|
||||||
nextarg = (i < (argc-1)) ? argv[i+1] : NULL;
|
|
||||||
|
|
||||||
res = getparameter(flag, nextarg, &passarg, config);
|
|
||||||
if(!res && passarg) /* we're supposed to skip this */
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
bool used;
|
|
||||||
/* just add the URL please */
|
|
||||||
res = getparameter((char *)"--url", argv[i], &used, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(res) {
|
|
||||||
int retval = CURLE_OK;
|
|
||||||
if(res != PARAM_HELP_REQUESTED) {
|
|
||||||
const char *reason = param2text(res);
|
|
||||||
helpf(config->errors, "option %s: %s\n", orig_opt, reason);
|
|
||||||
retval = CURLE_FAILED_INIT;
|
|
||||||
}
|
|
||||||
res = retval;
|
|
||||||
goto quit_curl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config->userpwd && !config->xoauth2_bearer) {
|
if(config->userpwd && !config->xoauth2_bearer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user