mbox series

[RFC,nftables,0/4] Add Linenoise support to the CLI.

Message ID 20190916124203.31380-1-jeremy@azazel.net
Headers show
Series Add Linenoise support to the CLI. | expand

Message

Jeremy Sowden Sept. 16, 2019, 12:41 p.m. UTC
Sebastian Priebe [0] requested Linenoise support for the CLI as an
alternative to Readline, so I thought I'd have a go at providing it.
Linenoise is a minimal, zero-config, BSD licensed, Readline replacement
used in Redis, MongoDB, and Android [1].

 0 - https://lore.kernel.org/netfilter-devel/4df20614cd10434b9f91080d0862dd0c@de.sii.group/
 1 - https://github.com/antirez/linenoise/

The upstream repo doesn't contain the infrastructure for building or
installing libraries.  I've taken a look at how Redis and MongoDB handle
this, and they both include the upstream sources in their trees (MongoDB
actually uses a C++ fork, Linenoise NG [2]), so I've done the same.

 2 - https://github.com/arangodb/linenoise-ng

Initially, I added the Linenoise header to include/ and the source to
src/, but the compiler warning flags used by upstream differ from those
used by nftables, which meant that the compiler emitted warnings when
compiling the Linenoise source and I had to edit it to fix them.  Since
they were benign and editing the source would make it more complicated
to update from upstream in the future, I have, instead, chosen to put
everything in a separate linenoise/ directory with its own Makefile.am
and the same warning flags as upstream.

By default, the CLI continues to be build using Readline, but passing
`with-cli=linenoise` instead causes Linenoise to be used instead.

The first two patches do a bit of tidying; the third patch adds the
Linenoise sources; the last adds Linenoise support to the CLI.

Jeremy Sowden (4):
  configure: remove unused AC_SUBST macros.
  cli: remove unused declaration.
  cli: add upstream linenoise source.
  cli: add linenoise CLI implementation.

 Makefile.am                 |    7 +-
 configure.ac                |   20 +-
 include/cli.h               |    3 +-
 linenoise/.gitignore        |    6 +
 linenoise/LICENSE           |   25 +
 linenoise/Makefile.am       |   13 +
 linenoise/Makefile.upstream |    7 +
 linenoise/README.markdown   |  229 +++++++
 linenoise/example.c         |   74 +++
 linenoise/linenoise.c       | 1201 +++++++++++++++++++++++++++++++++++
 linenoise/linenoise.h       |   73 +++
 src/Makefile.am             |    6 +
 src/cli.c                   |   64 +-
 13 files changed, 1710 insertions(+), 18 deletions(-)
 create mode 100644 linenoise/.gitignore
 create mode 100644 linenoise/LICENSE
 create mode 100644 linenoise/Makefile.am
 create mode 100644 linenoise/Makefile.upstream
 create mode 100644 linenoise/README.markdown
 create mode 100644 linenoise/example.c
 create mode 100644 linenoise/linenoise.c
 create mode 100644 linenoise/linenoise.h

Comments

Pablo Neira Ayuso Sept. 20, 2019, 10:15 a.m. UTC | #1
On Mon, Sep 16, 2019 at 01:41:59PM +0100, Jeremy Sowden wrote:
> Sebastian Priebe [0] requested Linenoise support for the CLI as an
> alternative to Readline, so I thought I'd have a go at providing it.
> Linenoise is a minimal, zero-config, BSD licensed, Readline replacement
> used in Redis, MongoDB, and Android [1].
> 
>  0 - https://lore.kernel.org/netfilter-devel/4df20614cd10434b9f91080d0862dd0c@de.sii.group/
>  1 - https://github.com/antirez/linenoise/
> 
> The upstream repo doesn't contain the infrastructure for building or
> installing libraries.  I've taken a look at how Redis and MongoDB handle
> this, and they both include the upstream sources in their trees (MongoDB
> actually uses a C++ fork, Linenoise NG [2]), so I've done the same.
> 
>  2 - https://github.com/arangodb/linenoise-ng
> 
> Initially, I added the Linenoise header to include/ and the source to
> src/, but the compiler warning flags used by upstream differ from those
> used by nftables, which meant that the compiler emitted warnings when
> compiling the Linenoise source and I had to edit it to fix them.

Could you silent these warnings via CFLAGS just like we do with
mini-gmp.{c,h}? We already cache a copy of mini-gmp.c in the tree,
this would follow the same approach, just the source under src/ and
the header in include/.

> Since they were benign and editing the source would make it more
> complicated to update from upstream in the future, I have, instead,
> chosen to put everything in a separate linenoise/ directory with its
> own Makefile.am and the same warning flags as upstream.
> 
> By default, the CLI continues to be build using Readline, but passing
> `with-cli=linenoise` instead causes Linenoise to be used instead.

Probably good if you can also update 'nft -v' to display that nft is
compiled with/without mini-gmp and also with either
libreadline/linenoise.

> The first two patches do a bit of tidying; the third patch adds the
> Linenoise sources; the last adds Linenoise support to the CLI.

No objections, please update tests/build/ to check for this new
./configure option.

Thanks.
Jeremy Sowden Sept. 21, 2019, 11:07 a.m. UTC | #2
On 2019-09-20, at 12:15:20 +0200, Pablo Neira Ayuso wrote:
> On Mon, Sep 16, 2019 at 01:41:59PM +0100, Jeremy Sowden wrote:
> > Sebastian Priebe [0] requested Linenoise support for the CLI as an
> > alternative to Readline, so I thought I'd have a go at providing it.
> > Linenoise is a minimal, zero-config, BSD licensed, Readline
> > replacement used in Redis, MongoDB, and Android [1].
> >
> >  0 - https://lore.kernel.org/netfilter-devel/4df20614cd10434b9f91080d0862dd0c@de.sii.group/
> >  1 - https://github.com/antirez/linenoise/
> >
> > The upstream repo doesn't contain the infrastructure for building or
> > installing libraries.  I've taken a look at how Redis and MongoDB
> > handle this, and they both include the upstream sources in their
> > trees (MongoDB actually uses a C++ fork, Linenoise NG [2]), so I've
> > done the same.
> >
> >  2 - https://github.com/arangodb/linenoise-ng
> >
> > Initially, I added the Linenoise header to include/ and the source
> > to src/, but the compiler warning flags used by upstream differ from
> > those used by nftables, which meant that the compiler emitted
> > warnings when compiling the Linenoise source and I had to edit it to
> > fix them.
>
> Could you silent these warnings via CFLAGS just like we do with
> mini-gmp.{c,h}? We already cache a copy of mini-gmp.c in the tree,
> this would follow the same approach, just the source under src/ and
> the header in include/.

Ah, yes, thanks for the pointer.

> > Since they were benign and editing the source would make it more
> > complicated to update from upstream in the future, I have, instead,
> > chosen to put everything in a separate linenoise/ directory with its
> > own Makefile.am and the same warning flags as upstream.
> >
> > By default, the CLI continues to be build using Readline, but
> > passing `with-cli=linenoise` instead causes Linenoise to be used
> > instead.
>
> Probably good if you can also update 'nft -v' to display that nft is
> compiled with/without mini-gmp and also with either
> libreadline/linenoise.

Will do.

> > The first two patches do a bit of tidying; the third patch adds the
> > Linenoise sources; the last adds Linenoise support to the CLI.
>
> No objections, please update tests/build/ to check for this new
> ./configure option.

Will do.

J.