project-ideas icon indicating copy to clipboard operation
project-ideas copied to clipboard

Library for unix command line tools

Open FraMecca opened this issue 6 years ago • 9 comments

Description

The aim of this project is to create a library that aids in the development of command line applications in unix systems, mainly providing a unified interface for:

  • parsing command line flags and arguments
  • parsing environment variables
  • parsing configuration files
  • accessing standard locations for configuration files and user data

There are many specifications for cli arguments such as:

  • http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
  • https://www.gnu.org/prep/standards/html_node/Command_002dLine-Interfaces.html
  • http://catb.org/~esr/writings/taoup/html/ch10s05.html

Moreover common command line utilities adhere to freedesktop specifications for storing and accessing user data and configurations:

  • https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

There are already some experiments in this space, mainly:

  • https://github.com/burner/argsd
  • https://aliak00.github.io/dcli/dcli/program_options.html
  • https://github.com/mihails-strasuns/d-simpleconfig
  • https://github.com/jarro2783/cxxopts
  • https://github.com/burner/inifiled

Even if some of these libraries try to unify command line parsing and configuration file parsing, they either don't adhere to specifications or are not fully compliant. Moreover some cli utilities could take into consideration environment variables

This library should provide a unified api to parse configuration files from standard locations, environment variables and cli arguments (in this order). Moreover the library could provide support to multiple file configurations format (sdl, yaml, toml, etc...) and standardized system locations.

What are rough milestones of this project?

To be discussed

How does this project help the D community?

This project helps the D community by providing an higher level api than std.getopt and fulfills the common needs of developers that build cli utilities for unix systems.

Recommended skills

Knowledge of the GNU/Linux operating system, shell and common cli utilities.

Point of Contact

@FraMecca

References

See above links

<NG discussions, GitHub PRs, Bugzilla issues, ...>

FraMecca avatar May 11 '19 16:05 FraMecca

Suggestion: You might want to consider including a generic backend interface for config info. So that the config data specification is/can be decoupled from the source of the config information. The config info can then be provided by / stored in several/multiple formats like commandline args, ini file, json, xml, yaml, database (sql, nosql), ldap, directory structure, fuse, etc. It might even allow the user to freely choose the desired config backend and convert between them if/when necessary.

reference #22 reference #21

dkgroot avatar May 11 '19 16:05 dkgroot

I agree with @dkgroot about having a generic and extensible library for app configuration. For an example of such API, check https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2.

PetarKirov avatar May 11 '19 16:05 PetarKirov

  • config Interface definition -> in the standard (phobos)
  • reference implementation -> in the standard (phobos)
  • other implementations can start outside and might mature into phobos later on.

If you write your own backend impl and follow the definition it can/should be used by any/everyone. The interface requirements would have to provide for minimal and extended requirements. Some backend formats might not able to do everything the others can do. For example standard ini files don't have a concept of includes, arrays/maps (like json), or references (like yaml/xml).

Also please add: https://github.com/burner/inifiled to the list :-)

dkgroot avatar May 11 '19 16:05 dkgroot

You can see this project: https://github.com/huntlabs/hunt-console

zoujiaqing avatar Aug 19 '19 06:08 zoujiaqing

Take a look at this CLI package for Golang: https://github.com/urfave/cli/blob/master/docs/v2/manual.md

greenduck avatar Feb 18 '20 16:02 greenduck

@greenduck exactly what I had in mind. This project could be renamed: Port go cli library to D.

The only difference would be the fact that D could accomplish more at compile time and could use pegged in a lot of places where the go cli library do parsing at runtime.

FraMecca avatar May 12 '20 08:05 FraMecca

Hi! I've been learning the D language and recently came across SAoC. I have some experience in PL-development (with C++) and have worked on the Pallene compiler with GSoC before (C/Lua). I want to try my hand at this issue (seeing it hasn't been closed yet).

Since it's been a while and this issue hasn't received a lot of activity, would it be fair to assume that this problem is still open to contribution?

I've worked with/on arg-parsers before and have a braindump I wanted to post, thought I should ask first.

Cheers!

srijan-paul avatar Jul 27 '21 17:07 srijan-paul

thank you for taking in interest. Maybe have a look at the modules in D's standard library phobos https://dlang.org/phobos/index.html and the community packages in code.dlang.org.

We already have a couple of command line argument parsers, so we are properly good on that front, but having a structured view at what other lang/OSs/libs can do and what D already can will every likely shows things that can be improved.

burner avatar Jul 27 '21 22:07 burner

Thanks for the heads up! I'll take a look at those ^^

srijan-paul avatar Jul 29 '21 07:07 srijan-paul