Commit 41dc8c43 authored by Daniel Salzman's avatar Daniel Salzman

knotc: use stdout as a default for configuration export

parent 4adfcd59
......@@ -174,8 +174,8 @@ Check the server configuration. (*)
Import a configuration file into the configuration database. Ensure the
server is not using the configuration database! (*)
.TP
\fBconf\-export\fP \fIfilename\fP
Export the configuration database into a config file. (*)
\fBconf\-export\fP [\fIfilename\fP]
Export the configuration database into a config file or stdout. (*)
.TP
\fBconf\-list\fP [\fIitem\fP]
List the configuration database sections or section items.
......
......@@ -151,8 +151,8 @@ Actions
Import a configuration file into the configuration database. Ensure the
server is not using the configuration database! (*)
**conf-export** *filename*
Export the configuration database into a config file. (*)
**conf-export** [*filename*]
Export the configuration database into a config file or stdout. (*)
**conf-list** [*item*]
List the configuration database sections or section items.
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -867,7 +867,7 @@ int conf_export(
const char *file_name,
yp_style_t style)
{
if (conf == NULL || file_name == NULL) {
if (conf == NULL) {
return KNOT_EINVAL;
}
......@@ -878,7 +878,7 @@ int conf_export(
return KNOT_ENOMEM;
}
FILE *fp = fopen(file_name, "w");
FILE *fp = (file_name != NULL) ? fopen(file_name, "w") : stdout;
if (fp == NULL) {
free(buff);
return knot_map_errno();
......@@ -923,7 +923,9 @@ int conf_export(
ret = KNOT_EOK;
export_error:
fclose(fp);
if (file_name != NULL) {
fclose(fp);
}
free(buff);
return ret;
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -274,7 +274,7 @@ int conf_import(
* Exports configuration to textual file.
*
* \param[in] conf Configuration.
* \param[in] file_name Output filename.
* \param[in] file_name Output filename (stdout is used if NULL).
* \param[in] style Formatting style.
*
* \return Error code, KNOT_EOK if success.
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -978,17 +978,24 @@ static int cmd_conf_import(cmd_args_t *args)
static int cmd_conf_export(cmd_args_t *args)
{
int ret = check_args(args, 1, 1);
int ret = check_args(args, 0, 1);
if (ret != KNOT_EOK) {
return ret;
}
log_debug("exporting confdb into file '%s'", args->argv[0]);
// Stdout is the default output file.
const char *file_name = NULL;
if (args->argc > 0) {
file_name = args->argv[0];
log_debug("exporting confdb into file '%s'", file_name);
}
ret = conf_export(conf(), args->argv[0], YP_SNONE);
ret = conf_export(conf(), file_name, YP_SNONE);
if (ret == KNOT_EOK) {
log_info("OK");
if (args->argc > 0) {
log_info("OK");
}
} else {
log_error("export (%s)", knot_strerror(ret));
}
......@@ -1125,7 +1132,7 @@ static const cmd_help_t cmd_help_table[] = {
{ CMD_CONF_INIT, "", "Initialize the confdb. (*)" },
{ CMD_CONF_CHECK, "", "Check the server configuration. (*)" },
{ CMD_CONF_IMPORT, "<filename>", "Import a config file into the confdb. (*)" },
{ CMD_CONF_EXPORT, "<filename>", "Export the confdb into a config file. (*)" },
{ CMD_CONF_EXPORT, "[<filename>]", "Export the confdb into a config file or stdout. (*)" },
{ CMD_CONF_LIST, "[<item>...]", "List the confdb sections or section items." },
{ CMD_CONF_READ, "[<item>...]", "Get the item from the active confdb." },
{ CMD_CONF_BEGIN, "", "Begin a writing confdb transaction." },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment