Skip to content
This repository was archived by the owner on Feb 16, 2025. It is now read-only.
This repository was archived by the owner on Feb 16, 2025. It is now read-only.

Command-line tooling in C #4431

Open
Open

Description

@hannes99

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

Subcommands

  • basename
  • cache
  • cmerge
  • complete
  • convert
  • cp
  • dirname
  • editor
  • export
  • file
  • find
  • gen
  • get
  • global-mount/gmount
  • global-umount/gumount
  • list-commands
  • list-tools
  • ls
  • merge
  • meta-[get, ls, rm, set, show]
  • mount
  • mv
  • namespace
  • plugin-[check, info, list]
  • remount
  • rm
  • set
  • sget
  • shell
  • smount
  • spec-mount/smount
  • test
  • umount
  • validate

Related issues that should be solved in the process

Activity

  1. self-assigned this
    on Aug 9, 2022
  2. markus2330 commented on Aug 10, 2022

    @markus2330
    Contributor

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

    Some comments about the list above:

    • cmerge: should be "merged" with merge so that we have only one merge command, see Integrate new 3-way merge into tools #3131
    • Aliases should be removed (remove kdb aliases #3957), so in the list above " global-mount/gmount" -> only global-mount is relevant.
    • for export/import we get a new library written by @atmaxinger
    • for mount/umount we get a new library written by @flo91
    • validate is more historical, can be dropped
    • sget recommends an outdated approach, a specification with defaults should be preferred. Some command for scripts, however, would be very nice: some way to tell kdb get that command-line arguments and env variables should be interpreted via gopts.
    • basename, dirname and namespace should imho be grouped, e.g. key-basename, key-dirname and key-namespace

    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:

    • cmdline parser (we already discussed: it should be done with the gopts plugin, which probably needs improvements on the way)
    • common error handling across tools (same return values, same error text etc.) A currently unused lib for error handling was done for C++ by @flo91, see https://github.com/ElektraInitiative/libelektra/tree/master/src/libs/tools/src/errors
    • profiles (see kdb --help)
    • bookmarks (see kdb --help)
    • strategy handling, see master.libelektra.org/doc/help/elektra-merge-strategy.md (used by merge, editor, import, mount)
    • ansicolors (nice coloring of output, especially for errors)
    • facility to spawn subprocesses (external.cpp)
    • plugindatabase.cpp (also needed by @flo91)
    • specreader.cpp (might have overlap with what @flo91 does)

    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 #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?

  3. kodebach commented on Aug 10, 2022

    @kodebach
    Member

    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.

  4. flo91 commented on Oct 4, 2022

    @flo91
    Collaborator

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

  5. markus2330 commented on Oct 9, 2022

    @markus2330
    Contributor

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

  6. changed the title [-]Command-line tooling rewrite[/-] [+]Command-line tooling in C[/+] on May 2, 2023
  7. markus2330 commented on May 2, 2023

    @markus2330
    Contributor

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

  8. github-actions commented on May 2, 2024

    @github-actions

    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 💖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions