mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 10:40:11 +01:00
cli: generate setting docs from libnm-util/nm-setting-docs.xml
nmcli used the GParamSpec doc strings to get property descriptions, but they will be going away. Generate a .c file from the new XML setting docs file, and link that into nmcli.
This commit is contained in:
parent
07bb19a3bb
commit
8252ebd941
5 changed files with 113 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -218,6 +218,7 @@ valgrind-*.log
|
|||
/data/server.conf
|
||||
|
||||
/cli/src/nmcli
|
||||
/cli/src/settings-docs.c
|
||||
|
||||
/tui/newt/libnmt-newt.a
|
||||
/tui/nmtui
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ bin_PROGRAMS = \
|
|||
|
||||
AM_CPPFLAGS = \
|
||||
-I${top_srcdir} \
|
||||
-I${top_builddir} \
|
||||
-I${top_srcdir}/include \
|
||||
-I${top_builddir}/include \
|
||||
-I${top_srcdir}/libnm-util \
|
||||
|
|
@ -37,4 +38,13 @@ nmcli_LDADD = \
|
|||
$(top_builddir)/libnm-util/libnm-util.la \
|
||||
$(top_builddir)/libnm-glib/libnm-glib.la
|
||||
|
||||
if HAVE_INTROSPECTION
|
||||
settings-docs.c: settings-docs.xsl $(top_builddir)/libnm-util/nm-setting-docs.xml
|
||||
$(AM_V_GEN) xsltproc --output $@ $^
|
||||
|
||||
BUILT_SOURCES = settings-docs.c
|
||||
endif
|
||||
|
||||
DISTCLEANFILES = settings-docs.c
|
||||
|
||||
EXTRA_DIST = settings-docs.c settings-docs.xsl
|
||||
|
|
|
|||
86
cli/src/settings-docs.xsl
Normal file
86
cli/src/settings-docs.xsl
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
|
||||
<xsl:output
|
||||
method="text"
|
||||
doctype-public="-//OASIS//DTD DocBook XML V4.3//EN"
|
||||
doctype-system="http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
|
||||
/>
|
||||
|
||||
<xsl:template match="nm-setting-docs">/* Generated file. Do not edit. */
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const char *docs;
|
||||
} NmcPropertyDesc;
|
||||
<xsl:apply-templates select="setting" mode="properties"><xsl:sort select="@name"/></xsl:apply-templates>
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
NmcPropertyDesc *properties;
|
||||
int n_properties;
|
||||
} NmcSettingDesc;
|
||||
|
||||
NmcSettingDesc all_settings[] = {
|
||||
<xsl:apply-templates select="setting" mode="settings"><xsl:sort select="@name"/></xsl:apply-templates>
|
||||
};
|
||||
|
||||
static int
|
||||
find_by_name (gconstpointer keyv, gconstpointer cmpv)
|
||||
{
|
||||
const char *key = keyv;
|
||||
struct { const char *name; gpointer data; } *cmp = (gpointer)cmpv;
|
||||
|
||||
return strcmp (key, cmp->name);
|
||||
}
|
||||
|
||||
static const char *
|
||||
nmc_setting_get_property_doc (NMSetting *setting, const char *prop)
|
||||
{
|
||||
NmcSettingDesc *setting_desc;
|
||||
NmcPropertyDesc *property_desc;
|
||||
|
||||
setting_desc = bsearch (nm_setting_get_name (setting),
|
||||
all_settings, G_N_ELEMENTS (all_settings),
|
||||
sizeof (NmcSettingDesc), find_by_name);
|
||||
if (!setting_desc)
|
||||
return NULL;
|
||||
property_desc = bsearch (prop,
|
||||
setting_desc->properties, setting_desc->n_properties,
|
||||
sizeof (NmcPropertyDesc), find_by_name);
|
||||
if (!property_desc)
|
||||
return NULL;
|
||||
return property_desc->docs;
|
||||
}
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="setting" mode="properties">
|
||||
NmcPropertyDesc setting_<xsl:value-of select="translate(@name,'-','_')"/>[] = {<xsl:apply-templates select="property"><xsl:sort select="@name"/></xsl:apply-templates>
|
||||
};
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="property">
|
||||
<xsl:variable name="docs">
|
||||
<xsl:call-template name="escape_quotes">
|
||||
<xsl:with-param name="string" select="@description"/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
{ "<xsl:value-of select="@name"/>", "<xsl:value-of select="$docs"/>" },</xsl:template>
|
||||
|
||||
<xsl:template match="setting" mode="settings">
|
||||
{ "<xsl:value-of select="@name"/>", setting_<xsl:value-of select="translate(@name,'-','_')"/>, <xsl:value-of select="count(./property)"/> },</xsl:template>
|
||||
|
||||
<xsl:template name="escape_quotes">
|
||||
<xsl:param name="string" />
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($string, '"')">
|
||||
<xsl:value-of select="substring-before($string, '"')" />\"<xsl:call-template name="escape_quotes"><xsl:with-param name="string" select="substring-after($string, '"')" /></xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$string" />
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <net/if_arp.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
|
@ -6367,10 +6368,16 @@ nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_INTROSPECTION
|
||||
#include "settings-docs.c"
|
||||
#else
|
||||
#define nmc_setting_get_property_doc(setting, prop) "(not available)"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Create a description string for a property.
|
||||
*
|
||||
* It returns a description got from properties blurb, concatenated with
|
||||
* It returns a description got from property documentation, concatenated with
|
||||
* nmcli specific description (if it exists).
|
||||
*
|
||||
* Returns: property description or NULL on failure. The caller must free the string.
|
||||
|
|
@ -6378,9 +6385,8 @@ nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop)
|
|||
char *
|
||||
nmc_setting_get_property_desc (NMSetting *setting, const char *prop)
|
||||
{
|
||||
GParamSpec *spec;
|
||||
const NmcPropertyFuncs *item;
|
||||
const char *setting_desc = "";
|
||||
const char *setting_desc = NULL;
|
||||
const char *setting_desc_title = "";
|
||||
const char *nmcli_desc = NULL;
|
||||
const char *nmcli_desc_title = "";
|
||||
|
|
@ -6388,11 +6394,9 @@ nmc_setting_get_property_desc (NMSetting *setting, const char *prop)
|
|||
|
||||
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
|
||||
|
||||
spec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop);
|
||||
if (spec) {
|
||||
setting_desc = g_param_spec_get_blurb (spec);
|
||||
setting_desc = nmc_setting_get_property_doc (setting, prop);
|
||||
if (setting_desc)
|
||||
setting_desc_title = _("[NM property description]");
|
||||
}
|
||||
|
||||
item = nmc_properties_find (nm_setting_get_name (setting), prop);
|
||||
if (item && item->describe_func) {
|
||||
|
|
@ -6402,7 +6406,8 @@ nmc_setting_get_property_desc (NMSetting *setting, const char *prop)
|
|||
}
|
||||
|
||||
return g_strdup_printf ("%s\n%s\n%s%s%s%s",
|
||||
setting_desc_title, setting_desc,
|
||||
setting_desc_title,
|
||||
setting_desc ? setting_desc : "",
|
||||
nmcli_nl, nmcli_desc_title, nmcli_nl,
|
||||
nmcli_desc ? nmcli_desc : "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -267,6 +267,9 @@ AC_SUBST(GUDEV_CFLAGS)
|
|||
AC_SUBST(GUDEV_LIBS)
|
||||
|
||||
GOBJECT_INTROSPECTION_CHECK([0.9.6])
|
||||
if test -z "$INTROSPECTION_MAKEFILE"; then
|
||||
AC_DEFINE(HAVE_INTROSPECTION, [1], [Define if you have gobject-introspection])
|
||||
fi
|
||||
|
||||
# Qt4
|
||||
PKG_CHECK_MODULES(QT, [QtCore >= 4 QtDBus QtNetwork], [have_qt=yes],[have_qt=no])
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue