Matthias Beyer
b66371f79b
With this change applied, libimagstore does not export backend representing types anymore. This change is necessar because when we want to switch the `StoreId` implementation from "complex and stateful" to "Stateless and Cow<'_, &str>", we need to be able to have a type which represents a "`StoreId` plus the path of the Store itself". This "the path of the Store itself" is passed around as reference, to minimize runtime impact. Because such a type should not be exported by the libimagstore crate, we make it `pub(crate)` internally. But because the backend APIs also have to use this type, we would export the (private) type in the APIs of the backend. Because of that we make the backend API also non-visible to crate users, which also decreases the surface of the libimagstore API itself. Besides: Remove function `Link::with_base()` which is not needed anymore (was used in tests only). Signed-off-by: Matthias Beyer <mail@beyermatthias.de> |
||
---|---|---|
.. | ||
src | ||
.gitignore | ||
Cargo.toml | ||
README.md |
libimagrt
This library provides utility functionality for the modules and the binary frontends, such as reading and parsing the configuration file, a builder helper for the commandline interface and such.
It also contains the store object and creates it from configuration.
the libimagrt::runtime::Runtime
object is the first complex object that comes
to live in a imag binary.
IO with libimagrt
libimagrt also provides IO primitives which should be used by all imag tools and libraries:
The IO story in imag is pretty easy. As imag is mainly a CLI tool, IO is either
stdout
or stderr
and stdin
.
Output
libimagrt provides getters for an output stream for "normal" output, like logging, status information, etc. It also provides an output for "touched entries".
Whenever an imag tool touches an entry in any way (either reading or writing), it should report this to libimagrt. libimagrt then does "the right thing" which is printing it to stdout or swallowing the output. Normal output (logging, status information, explicitely queried information) goes to the right sink automatically, that is:
-
If the user provides the appropriate flags, normal output goes to
stderr
and "touched entries" go tostdout
. This allows a user to 'chain' imag calls. -
If the user does not provide these flags, normal output goes to
stdout
(for piping to other tools, e.g.grep
) and "touched entries" are not printed. -
stdin
can be used for reading store-ids which shall be processed by an imag tool. For exampleimag-tag
can receive a list of entries to add tags to viastdin
like this:echo some/entry some/other | imag tag -I add sometag
.
With these two settings in place, calls to imag can be chained and mixed with external tools pretty easily:
imag -O ids where 'some.header == 1' | \
imag -I -O tag add foo | \
imag -I -O category set bar | \
fzf | \
imag -I tag add baz
The first line gets all imag entries where some.header
equals 1
. The touched
entries are printed to stdout
(-O
).
The second line tags all entries which are passed via stdin
(-I
) with foo
and prints them to stdout
(-O
)
The third line sets the category for all entries which are passed via stdin
with bar
and prints them to stdout
.
The fourth line calls the fzf
program and lets the user select one entry
and the last line reads that entry via stdin
and tags it with baz
.
Automatically detecting the appropriate input/output settings is possible, but
hidden behind a environment-flag, as it is considered experimental.
To test this, set IMAG_IO_EXPERIMENTAL=1
in your environment.
Note that stdin
may be detected as "store id stream" when it is actually not.
libimagrt
can take care of this when passing --interactive
.
Input
libimagrt
also provides primitives for input. As documented in the paragraph
on "Output", imag tools may get store ids passed via stdin
.
Hence, imag tools may/can not interactive when passing store ids via stdin
.
libimagrt
provides functionality to query data from the user. These functions
automatically fail if the user passes store-ids via stdin
.
The next paragraph documents the details of this and may be skipped.
The user tells imag that stdin
contains store-ids by setting the -I
(--ids-in
) flag on the commandline. If that flag is given, the interactive
functionality of libimagrt automatically returns an Err(_)
which can be used
to tell the user what happened and exit the program accordingly.
The user may also provide --interactive
to tell imag via libimagrt that
stdin
is indeed not a stream of store-ids even if a pipe is detected.
Long-term TODO
- Merge with
libimagstore