mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-06-11 12:56:21 +09:00
options: add -q quiet flag to CLI getopt
Signed-off-by: Shreyas Mahajan <shreyasmahajan05@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
committed by
Jakub Jelen
parent
b371214209
commit
152fc6633e
@@ -178,6 +178,7 @@ usage(void)
|
||||
" -p port : connect to port\n"
|
||||
" -o option : set configuration option (e.g., -o Compression=yes)\n"
|
||||
" -r : use RSA to verify host public key\n"
|
||||
" -q : quiet mode\n"
|
||||
" -F file : parse configuration file instead of default one\n"
|
||||
" -E file : append debug logs to a log file instead of stderr\n"
|
||||
#ifdef WITH_PCAP
|
||||
|
||||
@@ -1847,21 +1847,23 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv)
|
||||
char **tmp = NULL;
|
||||
size_t i = 0;
|
||||
int argc = *argcptr;
|
||||
int debuglevel = 0;
|
||||
int compress = 0;
|
||||
size_t current = 0;
|
||||
int opt_rc = 0;
|
||||
int saveoptind = optind; /* need to save 'em */
|
||||
int saveopterr = opterr;
|
||||
int opt;
|
||||
int rv;
|
||||
|
||||
/* Nothing to do here */
|
||||
/* Keep preconfigured global log level and let -v flags raise it further. */
|
||||
int verbosity = ssh_get_log_level();
|
||||
int verbosity_set = 0;
|
||||
if (argc <= 1) {
|
||||
return SSH_OK;
|
||||
}
|
||||
|
||||
opterr = 0; /* shut up getopt */
|
||||
while ((opt = getopt(argc, argv, "c:i:o:Cl:p:vb:r12")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "c:i:o:Cl:p:qvb:r12")) != -1) {
|
||||
switch(opt) {
|
||||
case 'l':
|
||||
user = optarg;
|
||||
@@ -1870,8 +1872,12 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv)
|
||||
port = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
debuglevel++;
|
||||
ssh_set_log_level(debuglevel);
|
||||
verbosity++;
|
||||
verbosity_set = 1;
|
||||
break;
|
||||
case 'q':
|
||||
verbosity = SSH_LOG_NOLOG;
|
||||
verbosity_set = 1;
|
||||
break;
|
||||
case 'r':
|
||||
break;
|
||||
@@ -1958,6 +1964,14 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv)
|
||||
*argcptr = current + 1;
|
||||
SAFE_FREE(save);
|
||||
|
||||
if (verbosity_set) {
|
||||
verbosity = MIN(verbosity, SSH_LOG_FUNCTIONS);
|
||||
rv = ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
|
||||
if (rv < 0) {
|
||||
return SSH_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (compress) {
|
||||
if (ssh_options_set(session, SSH_OPTIONS_COMPRESSION, "yes") < 0) {
|
||||
return SSH_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user