ElektraInitiative / libelektra

Elektra serves as a universal and secure framework to access configuration settings in a global, hierarchical key database.
https://www.libelektra.org
BSD 3-Clause "New" or "Revised" License
208 stars 123 forks source link

Command-line tooling in C #4431

Open hannes99 opened 1 year ago

hannes99 commented 1 year ago

Rewrite the kdb cli tool from C++ to C.

Subcommands

Related issues that should be solved in the process

markus2330 commented 1 year ago

Thank you for creating the issues! (In particular #4432 is very good work, I see you are already diving into Elektra! :rocket:).

Some comments about the list above:

In the list above, foundational parts are missing (the ones that do not have a command by itself). Have a look in the source folder https://master.libelektra.org/src/tools/kdb what these foundation parts could be. Without any guarantee on completeness:

Coordination work can be done, as necessary, in the issues and also in the meetings all three weeks.

Btw. it would be nice if the source files are named like the command, so meta-ls.c (and not metals.c).

Btw2. have a look at https://github.com/ElektraInitiative/libelektra/issues/539. There should be some way with our gopts to do such things (I am not sure if/how POSIXLY_CORRECT is supported). Please add test more cases for kdb, including tests for command-line parsing.

Another feature we might want to solve in this reimplementation is #1610. It needs, however, first some library support. So let us keep this in the background as nice-to-have.

Then there is the question what should happen with kdb-gen which probably would be hard to rewrite and https://github.com/x86-64/mustache-c seems to be dead (last update 2019). I would suggest we make gen an extra tool (to be moved to src/tools/gen). I think this is fine as kdb gen is not used on embedded systems as it is a developer tool. So C++ should be fine. @kodebach What do you think about kdb gen?

kodebach commented 1 year ago

ansicolors (nice coloring of output, especially for errors)

To add to this: coloring should only happen, when outputting to a TTY (see isatty(3)).

Btw. it would be nice if the source files are named like the command, so meta-ls.c (and not metals.c).

If we go with nested commands (#539), we could also use a folder structure (e.g. meta/ls.c).

There should be some way with our gopts to do such things (I am not sure if/how POSIXLY_CORRECT is supported).

See examples/goptsCommands.c for example code. It's also explained in the docs.

As explained in the docs, when using sub-commands the position of options like -v matters and can change behaviour.

@kodebach What do you think about kdb gen?

Yeah, I don't think rewriting kdb gen as part of this makes sense. For now I'd also say put it into a separate src/tools/gen that is installed somewhere in e.g. /usr/share (not /usr/bin) and can still be invoked as kdb gen (i.e. the C code for kdb gen is just an exec to call the C++ executable if it is installed).

If we want to get rid of the C++ code in the long run, we could switch to Rust. In a quick search I found https://github.com/sunng87/handlebars-rust, which is a library for Handlebars templates (which should be mostly compatible with our Mustache templates, i.e. require little to no change in the templates). The Rust code could be put into a (self-contained) library and called via a C API. Rewriting the kdb gen code in C is probably not worth it.

flo91 commented 1 year ago

@markus2330 Maybe the code for some subcommands can also be rewritten as part of the FLOSS course.

markus2330 commented 1 year ago

I don't think that without the framework as basis anything can be done by someone else than @hannes99.

markus2330 commented 1 year ago

We should add the C tooling as an alternative tool, I think we can call it ckdb.

github-actions[bot] commented 2 months ago

I mark this stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping by writing a message here or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart: