All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft] main: add more information to `nft -V`.
@ 2020-03-03 23:23 Pablo Neira Ayuso
  2020-03-04  8:57 ` Jeremy Sowden
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-03 23:23 UTC (permalink / raw)
  To: netfilter-devel; +Cc: jeremy

From: Jeremy Sowden <jeremy@azazel.net>

In addition to the package-version and release-name, output the CLI
implementation (if any) and whether mini-gmp was used, e.g.:

    $ ./src/nft -V
    nftables v0.9.3 (Topsy)
      cli:          linenoise
      minigmp:      no

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
Hi Jeremy et al.

I'm revisiting this one, it's basically your patch with a few mangling.

I wonder if it's probably a good idea to introduce a long version mode.
I have seen other tools providing more verbose information about all
build information.

The idea would be to leave -v/--version as it is, and introduce -V
which would be more verbose.

Thanks.

 src/Makefile.am |  3 +++
 src/main.c      | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 9142ab4484f2..b4b9142bf6b0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -13,6 +13,9 @@ endif
 if BUILD_XTABLES
 AM_CPPFLAGS += ${XTABLES_CFLAGS}
 endif
+if BUILD_MINIGMP
+AM_CPPFLAGS += -DHAVE_MINIGMP
+endif
 
 AM_CFLAGS = -Wall								\
 	    -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations	\
diff --git a/src/main.c b/src/main.c
index 6ab1b89f4dd5..6a88e777cc1f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -27,6 +27,7 @@ static struct nft_ctx *nft;
 enum opt_vals {
 	OPT_HELP		= 'h',
 	OPT_VERSION		= 'v',
+	OPT_VERSION_LONG	= 'V',
 	OPT_CHECK		= 'c',
 	OPT_FILE		= 'f',
 	OPT_INTERACTIVE		= 'i',
@@ -46,7 +47,7 @@ enum opt_vals {
 	OPT_TERSE		= 't',
 	OPT_INVALID		= '?',
 };
-#define OPTSTRING	"+hvd:cf:iI:jvnsNaeSupypTt"
+#define OPTSTRING	"+hvVd:cf:iI:jvnsNaeSupypTt"
 
 static const struct option options[] = {
 	{
@@ -141,6 +142,7 @@ static void show_help(const char *name)
 "Options:\n"
 "  -h, --help			Show this help\n"
 "  -v, --version			Show version information\n"
+"  -V				Show extended version information\n"
 "\n"
 "  -c, --check			Check commands validity without actually applying the changes.\n"
 "  -f, --file <filename>		Read input from <filename>\n"
@@ -164,6 +166,31 @@ static void show_help(const char *name)
 	name, DEFAULT_INCLUDE_PATH);
 }
 
+static void show_version(void)
+{
+	const char *cli, *minigmp;
+
+#if defined(HAVE_LIBREADLINE)
+	cli = "readline";
+#elif defined(HAVE_LIBLINENOISE)
+	cli = "linenoise";
+#else
+	cli = "no";
+#endif
+
+#if defined(HAVE_MINIGMP)
+	minigmp = "yes";
+#else
+	minigmp = "no";
+#endif
+
+	printf("%s v%s (%s)\n"
+	       "  cli:		%s\n"
+	       "  minigmp:	%s\n",
+	       PACKAGE_NAME, PACKAGE_VERSION, RELEASE_NAME,
+	       cli, minigmp);
+}
+
 static const struct {
 	const char		*name;
 	enum nft_debug_level	level;
@@ -272,6 +299,9 @@ int main(int argc, char * const *argv)
 			printf("%s v%s (%s)\n",
 			       PACKAGE_NAME, PACKAGE_VERSION, RELEASE_NAME);
 			exit(EXIT_SUCCESS);
+		case OPT_VERSION_LONG:
+			show_version();
+			exit(EXIT_SUCCESS);
 		case OPT_CHECK:
 			nft_ctx_set_dry_run(nft, true);
 			break;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH nft] main: add more information to `nft -V`.
  2020-03-03 23:23 [PATCH nft] main: add more information to `nft -V` Pablo Neira Ayuso
@ 2020-03-04  8:57 ` Jeremy Sowden
  2020-03-05 11:47   ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Jeremy Sowden @ 2020-03-04  8:57 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel


[-- Attachment #1.1: Type: text/plain, Size: 3482 bytes --]

On 2020-03-04, at 00:23:41 +0100, Pablo Neira Ayuso wrote:
> From: Jeremy Sowden <jeremy@azazel.net>
>
> In addition to the package-version and release-name, output the CLI
> implementation (if any) and whether mini-gmp was used, e.g.:
>
>     $ ./src/nft -V
>     nftables v0.9.3 (Topsy)
>       cli:          linenoise
>       minigmp:      no
>
> Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
> Hi Jeremy et al.
>
> I'm revisiting this one, it's basically your patch with a few
> mangling.
>
> I wonder if it's probably a good idea to introduce a long version
> mode.  I have seen other tools providing more verbose information
> about all build information.
>
> The idea would be to leave -v/--version as it is, and introduce -V
> which would be more verbose.
>
> Thanks.

Fine by me.  Btw, I notice that OPTSTRING contains a couple of
duplicates.  I've attached a patch to remove them.  It applies on top of
this one.

>  src/Makefile.am |  3 +++
>  src/main.c      | 32 +++++++++++++++++++++++++++++++-
>  2 files changed, 34 insertions(+), 1 deletion(-)
>
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 9142ab4484f2..b4b9142bf6b0 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -13,6 +13,9 @@ endif
>  if BUILD_XTABLES
>  AM_CPPFLAGS += ${XTABLES_CFLAGS}
>  endif
> +if BUILD_MINIGMP
> +AM_CPPFLAGS += -DHAVE_MINIGMP
> +endif
>
>  AM_CFLAGS = -Wall								\
>  	    -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations	\
> diff --git a/src/main.c b/src/main.c
> index 6ab1b89f4dd5..6a88e777cc1f 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -27,6 +27,7 @@ static struct nft_ctx *nft;
>  enum opt_vals {
>  	OPT_HELP		= 'h',
>  	OPT_VERSION		= 'v',
> +	OPT_VERSION_LONG	= 'V',
>  	OPT_CHECK		= 'c',
>  	OPT_FILE		= 'f',
>  	OPT_INTERACTIVE		= 'i',
> @@ -46,7 +47,7 @@ enum opt_vals {
>  	OPT_TERSE		= 't',
>  	OPT_INVALID		= '?',
>  };
> -#define OPTSTRING	"+hvd:cf:iI:jvnsNaeSupypTt"
> +#define OPTSTRING	"+hvVd:cf:iI:jvnsNaeSupypTt"
>
>  static const struct option options[] = {
>  	{
> @@ -141,6 +142,7 @@ static void show_help(const char *name)
>  "Options:\n"
>  "  -h, --help			Show this help\n"
>  "  -v, --version			Show version information\n"
> +"  -V				Show extended version information\n"
>  "\n"
>  "  -c, --check			Check commands validity without actually applying the changes.\n"
>  "  -f, --file <filename>		Read input from <filename>\n"
> @@ -164,6 +166,31 @@ static void show_help(const char *name)
>  	name, DEFAULT_INCLUDE_PATH);
>  }
>
> +static void show_version(void)
> +{
> +	const char *cli, *minigmp;
> +
> +#if defined(HAVE_LIBREADLINE)
> +	cli = "readline";
> +#elif defined(HAVE_LIBLINENOISE)
> +	cli = "linenoise";
> +#else
> +	cli = "no";
> +#endif
> +
> +#if defined(HAVE_MINIGMP)
> +	minigmp = "yes";
> +#else
> +	minigmp = "no";
> +#endif
> +
> +	printf("%s v%s (%s)\n"
> +	       "  cli:		%s\n"
> +	       "  minigmp:	%s\n",
> +	       PACKAGE_NAME, PACKAGE_VERSION, RELEASE_NAME,
> +	       cli, minigmp);
> +}
> +
>  static const struct {
>  	const char		*name;
>  	enum nft_debug_level	level;
> @@ -272,6 +299,9 @@ int main(int argc, char * const *argv)
>  			printf("%s v%s (%s)\n",
>  			       PACKAGE_NAME, PACKAGE_VERSION, RELEASE_NAME);
>  			exit(EXIT_SUCCESS);
> +		case OPT_VERSION_LONG:
> +			show_version();
> +			exit(EXIT_SUCCESS);
>  		case OPT_CHECK:
>  			nft_ctx_set_dry_run(nft, true);
>  			break;
> --
> 2.11.0

J.

[-- Attachment #1.2: 0001-main-remove-duplicates-from-option-string.patch --]
[-- Type: text/x-diff, Size: 841 bytes --]

From a0ddf69b9ef82ccc3f3c3174f960da3d58201e31 Mon Sep 17 00:00:00 2001
From: Jeremy Sowden <jeremy@azazel.net>
Date: Wed, 4 Mar 2020 08:40:15 +0000
Subject: [PATCH] main: remove duplicates from option string.

The string of options passed to getopt_long(3) contains duplicates.
Update it to match the opt_vals enum which immediately precedes it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 src/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main.c b/src/main.c
index 6a88e777cc1f..90208691557f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -47,7 +47,7 @@ enum opt_vals {
 	OPT_TERSE		= 't',
 	OPT_INVALID		= '?',
 };
-#define OPTSTRING	"+hvVd:cf:iI:jvnsNaeSupypTt"
+#define OPTSTRING	"+hvVcf:iI:jnsNSd:aeuypTt"
 
 static const struct option options[] = {
 	{
-- 
2.25.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH nft] main: add more information to `nft -V`.
  2020-03-04  8:57 ` Jeremy Sowden
@ 2020-03-05 11:47   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-05 11:47 UTC (permalink / raw)
  To: Jeremy Sowden; +Cc: netfilter-devel

On Wed, Mar 04, 2020 at 08:57:35AM +0000, Jeremy Sowden wrote:
> On 2020-03-04, at 00:23:41 +0100, Pablo Neira Ayuso wrote:
> > From: Jeremy Sowden <jeremy@azazel.net>
> >
> > In addition to the package-version and release-name, output the CLI
> > implementation (if any) and whether mini-gmp was used, e.g.:
> >
> >     $ ./src/nft -V
> >     nftables v0.9.3 (Topsy)
> >       cli:          linenoise
> >       minigmp:      no
> >
> > Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> > Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> > ---
> > Hi Jeremy et al.
> >
> > I'm revisiting this one, it's basically your patch with a few
> > mangling.
> >
> > I wonder if it's probably a good idea to introduce a long version
> > mode.  I have seen other tools providing more verbose information
> > about all build information.
> >
> > The idea would be to leave -v/--version as it is, and introduce -V
> > which would be more verbose.
> >
> > Thanks.
> 
> Fine by me.  Btw, I notice that OPTSTRING contains a couple of
> duplicates.  I've attached a patch to remove them.  It applies on top of
> this one.

Thanks, I have applied these two patches.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-05 11:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-03 23:23 [PATCH nft] main: add more information to `nft -V` Pablo Neira Ayuso
2020-03-04  8:57 ` Jeremy Sowden
2020-03-05 11:47   ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.