occtl: added option --no-pager

This commit is contained in:
Nikos Mavrogiannopoulos
2015-07-03 15:36:38 +02:00
parent 7b87fa4459
commit 49de6d0586
5 changed files with 23 additions and 5 deletions

View File

@@ -40,6 +40,13 @@ flag = {
doc = "";
};
flag = {
name = no-pager;
value = n;
descrip = "No pager will be used over output data";
doc = "";
};
doc-section = {
ds-type = 'SYNOPSIS';

View File

@@ -39,10 +39,13 @@ char* pager;
}
/* Always succeeds */
FILE* pager_start(void)
FILE* pager_start(cmd_params_st *params)
{
FILE *fp;
if (params && params->no_pager != 0)
return stdout;
#ifdef HAVE_ISATTY
if (isatty(STDOUT_FILENO) == 0)
return stdout;

View File

@@ -542,7 +542,7 @@ int handle_list_users_cmd(struct unix_ctx *ctx, const char *arg, cmd_params_st *
entries_clear();
out = pager_start();
out = pager_start(params);
ret = send_cmd(ctx, CTL_CMD_LIST, NULL, NULL, NULL, &raw);
if (ret < 0) {
@@ -633,7 +633,7 @@ int handle_list_banned_cmd(struct unix_ctx *ctx, const char *arg, cmd_params_st
ip_entries_clear();
out = pager_start();
out = pager_start(params);
ret = send_cmd(ctx, CTL_CMD_LIST_BANNED, NULL, NULL, NULL, &raw);
if (ret < 0) {
@@ -750,7 +750,7 @@ int common_info_cmd(UserListRep * args, FILE *out, cmd_params_st *params)
unsigned init_pager = 0;
if (out == NULL) {
out = pager_start();
out = pager_start(params);
init_pager = 1;
}

View File

@@ -545,6 +545,13 @@ int main(int argc, char **argv)
argv += 1;
argc -= 1;
} else if (argv[1][1] == 'n'
|| (argv[1][1] == '-' && argv[1][2] == 'n')) {
params.no_pager = 1;
argv += 1;
argc -= 1;
} else if (argv[1][1] == 'v'
|| (argv[1][1] == '-' && argv[1][2] == 'v')) {
version();

View File

@@ -20,9 +20,10 @@
typedef struct cmd_params_st {
unsigned json;
unsigned no_pager;
} cmd_params_st;
FILE* pager_start(void);
FILE* pager_start(cmd_params_st *params);
void pager_stop(FILE* fp);
void print_time_ival7(char output[MAX_TMPSTR_SIZE], time_t t1, time_t t2);
void print_iface_stats(const char *iface, time_t since, FILE * out, cmd_params_st *params, unsigned have_more);