Commit Graph

815 Commits

Author SHA1 Message Date
Matthias Beyer 8a4bc0eba4 Simplify implementation of Wiki::all_ids()
This way we alter the underlying iterator for all wiki entries to only
iterate in the "wiki" collection of the store, which results in fewer
disk access because the internal iterator does not yield all pathes from
the store before filtering them.

Code which was used to implement the filter was removed (also from the
public interface of the library).

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-11 03:22:56 +01:00
Matthias Beyer c29e05bc25 Simplify implementation of ContactStore::all_contacts()
This way we alter the underlying iterator for all contacts to only
iterate in the "contact" collection of the store, which results in fewer
disk access because the internal iterator does not yield all pathes from
the store before filtering them.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-11 03:22:56 +01:00
Matthias Beyer eed577db15 Add trace!() call to show config when runtime initializes
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-11 03:22:56 +01:00
Matthias Beyer f1a639ea8c Change id reporting API to return ExitCode
Because this API only errors when write!() errors occur, we can return
the exit code as an error here.

This way the user of the API can immediately exit if there was an IO
error, but the API automatically takes care of the right return value,
returning (exiting) with zero (0) if there was an "Broken pipe" error
and with one (1) otherwise, which is the expected behaviour here.

All calls to that API were changed accordingly.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-11 03:22:56 +01:00
Matthias Beyer 19912f5e88 Add Is::remove_isflag() for removing header flags
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-11 03:22:56 +01:00
Matthias Beyer 03e0864268 Merge branch 'unnamed-annotations' into master-ff
This merge adds several patches to improve libimagannotation and
imag-annotate.
2019-02-10 17:07:35 +01:00
Matthias Beyer d8cd10a384 Remove iterator types
With this patch, libimagentryannotation does not have special iterator
types anymore. This makes the whole thing more comfortable to use.

In imag-annotate, the parameter for the functioncall was removed.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-10 01:00:33 +01:00
Matthias Beyer ed01f8b463 Make annotations unnamed (automatically UUID named)
It makes no sense to name annotations, a user only cares about whether
there are annotations or not, or their contents. A name has no meaning
in this context.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-10 00:58:21 +01:00
Matthias Beyer d936b611fc Fix config override mechanism
The bug was that we did not actually _set_ the new value.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-10 00:47:41 +01:00
Matthias Beyer 0f32471a03 Merge branch 'runtime-io-features' into master-ff 2019-02-09 23:42:09 +01:00
Matthias Beyer afe275692e Fix: Do not use deprecated StoreId::exists() function
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-09 01:03:28 +01:00
Matthias Beyer e4ef6f0649 Remove log-destination-override features
This removes the feature to be able to override log destinations from
the commandline.

This feature is removed because the --override-config feature from the
runtime already contains this functionality. It is a little more complex
to use, though this is a feature hardly used at all, so I rather go for
less code (less complexity) here than feature bloat.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-05 01:03:39 +01:00
Matthias Beyer 3fbfb19419 Add runtime feature: Ignore id reporting
This feature gives the users of the Runtime API the possibility to check
whether the user wants the ID reporting to be ignored as well (and more
important) to override the default behaviour where the runtime assumes
that if STDOUT is a pipe, it is a pipe to an imag command.

Before, this would not have been possible:

    imag contact find Jonas --json | jq 'map(.fullname)'

because the runtime automatically prints the output of the command to
stderr and the touched IDs to stdout.
But now with this change, a user can override this default behaviour and
do:

    imag contact --ignore-ids find Jonas --json | jq 'map(.fullname)'

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-05 00:55:30 +01:00
Matthias Beyer 9185abcfa5 Update copyright years
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-01-03 18:41:36 +01:00
Matthias Beyer 4fe7fd366c Add Store::exists() for checking whether a StoreId exists as Entry
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-12-13 22:49:33 +01:00
Matthias Beyer d70a97191c Simplify Display impl for Storeid 2018-11-26 18:21:28 +01:00
Matthias Beyer 1ce780795a Do not use StoreId::local() here 2018-11-26 18:19:10 +01:00
Matthias Beyer dd388e53bb Reimplement StoreId::to_str() without erroring
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-26 18:15:08 +01:00
Matthias Beyer 496c06d15a Update lazy_static to 1.2
1.2 of lazy_static brings functionality to have no panics in the code,
which is what we try to have.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-11 13:05:55 +01:00
Matthias Beyer 9fca66aa89 Forbid unsafe code in all crates 2018-11-11 13:05:55 +01:00
Matthias Beyer 4e516ee19d Update version strings
...for the next release, which will be imag 0.10.0!

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-10 11:56:37 +01:00
Matthias Beyer 17d4123898 Update dependencies from git versions to proper versions.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-09 22:14:11 +01:00
Matthias Beyer 2cb46597f7 Add Option extensions for logging optional values
This patch adds the same extensions that we already have for
Result<T, E> also for Option<T>.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-09 21:48:26 +01:00
Matthias Beyer 9cfa9fc399 Make code more idomatic
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-09 21:48:25 +01:00
Matthias Beyer ed469f622a Make code more idomatic
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-09 21:48:02 +01:00
Matthias Beyer 029a3c448e Change WikiStore::create_wiki() interface
to also return the index page. This way a user of the library can use
the index page entry right away.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 20:35:18 +01:00
Matthias Beyer d1f087eb57 Change libimag{bookmark, entrylink} external linking
...to report newly created entries, so that we can re-use these new
entries in the library-using code (for example for ID reporting).

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 20:33:30 +01:00
Matthias Beyer c1c74973e3 Implement ID providing in libimagrt
With this patch, IDs can be fetched from the CLI via libimagrt. This
gives us the possibility to automatically handle "stdin provides IDs" in
libimagrt with less boilerplate in the binaries codebases.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 20:33:30 +01:00
Matthias Beyer db4e83f18f Implement ID reporting
This patch adds the id reporting feature to libimagrt::runtime::Runtime,
where processed ("touched") ids can be reported to the Runtime and then
get printed to stdout if stdout is a pipe.

Other output is automatically redirected to stderr if stdout is a pipe
now.
2018-11-06 20:33:00 +01:00
Matthias Beyer 44495d6efe Fix: Do not ignore errors in config anymore
The function already returns `Result<_>`, the only thing that had to be
done was refactoring the code for actually returning an error in that
case.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 20:04:47 +01:00
Matthias Beyer feea57679d Remove scope
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 20:04:47 +01:00
Matthias Beyer 21d411f57b Remove call to format_err!(), use err_msg() instead
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 20:04:47 +01:00
Matthias Beyer 09f0968755 Remove repetitive code by abstracting it
With this patch, the log level aggregation is abstracted away by using
zero sized types and a macro to implement the whole thing.

This does not alter functionality, but makes the code more readable.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 19:39:41 +01:00
Matthias Beyer 1ff1d85428 Remove unnecessary scope
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 19:08:00 +01:00
Matthias Beyer 1a70c523dc Remove indirection
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 19:03:19 +01:00
Matthias Beyer d493b04555 Remove scope for better readability
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 19:03:10 +01:00
Matthias Beyer 0e4cb59772 Format code
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 19:02:57 +01:00
Matthias Beyer 582fd10acb FS backend: Safe allocation of new PathBuf object
::stf::fs::create_dir_all() takes any ref to `Path`, which is what we
have here, so we can leave out the allocation of a new PathBuf object
here.

Also remove the match by a `if let Some(_)`, which increases the
readability a bit.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 18:37:53 +01:00
Matthias Beyer 88a4eee087 Adapt Store::get()/Store::create() to check cache before FS
With this change, the cache is tested before accessing the filesystem,
which probably increases the speed if the cache has the entry, because
we avoid the slow IO operation.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 18:35:17 +01:00
Matthias Beyer becfcd4180 Fix: In-Memory test backend: Actually remove the old entry on "move"
This fixes a really ugly bug where the in-memory backend for the store
did not remove the entry from the in-memory hashmap on "move", but
simply copied it from the old location to the new one.

That caused tests to fail after the fixes introduced for the
Store::get() function which checked the filesystem and the internal
cache whether an entry exists before the actual "get" operation, because
an old entry would still exist after a move (only in the testcases).

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Fixes: 09e8619cf5 ("libimagstore: Move from error-chain to failure")
2018-11-06 18:34:33 +01:00
Matthias Beyer daaa4fd9ca Make assert!() output more verbose
By printing the actual `Result<>` object that failed the assertion.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 18:17:46 +01:00
Matthias Beyer d982a657f8 Rewrite Debug for FileLockEntry
This changes the implementation of Debug for the FileLockEntry to be
more explanatory of how the entry actually looks like. It does not only
print the path of the store anymore, but also the location of the Entry.

Printing header and content would be still too much, tho.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 18:12:58 +01:00
Matthias Beyer e043304767 Add FileLockEntry-getter in Mail struct 2018-11-06 14:48:49 +01:00
Matthias Beyer e919435504 Fix: Remove call to deprecated function 2018-11-06 14:48:49 +01:00
Matthias Beyer cb0fcaffde Remove logging calls in favour of debug calls
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-01 21:35:40 +01:00
Matthias Beyer b4068bad0e Remove println call
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-01 21:33:18 +01:00
Matthias Beyer 1347784898 Merge branch 'safe-output'
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-01 21:22:26 +01:00
Matthias Beyer a45691ef27 Change test output to use debug!() 2018-11-01 20:37:02 +01:00
Matthias Beyer 1f5b490dd7 Change test output to use debug!() 2018-11-01 20:37:02 +01:00
Matthias Beyer 83876b7c2c Change test output to use debug!() 2018-11-01 20:37:02 +01:00
Matthias Beyer f01a262bdf Add debugging output in test via logger 2018-11-01 20:37:00 +01:00
Matthias Beyer 3bf3a8890b Add debugging output in test via logger 2018-11-01 20:36:46 +01:00
Matthias Beyer 91f5a33f5a Make "ask" functions get input and output streams
This way we can control where the input comes from and the output goes
to (like we want to with libimagrt).

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-01 20:30:12 +01:00
Matthias Beyer 993f83a31b Print Runtime errors to stderr 2018-11-01 20:26:25 +01:00
Matthias Beyer 7f0d5b8bfd Do not pass --rtp in test runtime 2018-11-01 13:19:14 +01:00
Matthias Beyer 71086b67d8 Add debug output in test runtime generating macro 2018-11-01 13:18:58 +01:00
Matthias Beyer 1a1cc885cc Merge branch 'rt-remove-default-value-verbosity'
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-01 00:05:42 +01:00
Matthias Beyer 351849e349 Fix: Remove default value for --verbose flag
This actually caused an error.

When executing `imag ids --verbose trace` for example, the `imag` binary
got the default value (as in `--verbose info`) supplied from clap. So
far, so good. Problem is that the implementation then forwarded that
flag to `imag-ids`, which resulted in the `--verbose` flag to be passed
_two times_ to `imag-ids`.

Somehow this is really strange, but it does not really matter. First of
all: A default of "Info" is still too high IMO. Default should be
warnings and errors, but no information printed. We like silent tools,
don't we?

Second is that the commandline argument forwarding mechanism of `imag`
is broken and this was a fix which helped debugging of the brokenness,
so this is acutally a step forward in this regard as well.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-31 23:13:07 +01:00
Matthias Beyer 9636cef7a8 Print (debugging) CLI when initializing runtime
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-31 23:11:06 +01:00
Matthias Beyer 59f16d0eab Add feature: Public logging initialization
This feature is required for the `imag` binary. It allows the binary to
use the imag internal logger for logging its own log output.

We need to be able to initialize the logger from an external module (in
all imag modules, the Runtime::new() implementation takes care of this,
but as we cannot use that in the `imag` binary itself, we allow this
method to be public behind a feature flag).

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-31 23:10:26 +01:00
Matthias Beyer 1d97e36c93 Add more CLI validators
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-31 17:15:29 +01:00
Matthias Beyer 366ca62eb9 Update dependency: mdcat: 0.8 -> 0.11 2018-10-31 17:15:29 +01:00
Matthias Beyer f4ff2ba250 libimagmail: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:29 +01:00
Matthias Beyer d3c0826188 libimagtodo: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:29 +01:00
Matthias Beyer 1956099e2e libimaglog: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 57f7a5a682 libimagtimetrack: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 3951bc7e5d libimagdiary: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 2a107477c0 libimagcontact: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 2dc17f8bea libimagwiki: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 9575bb933d libimagnotes: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer ede70581f3 libimaghabit: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer c11e971139 libimagbookmark: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer a1c65603dc libimagentrydatetime: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer f3e7f677b0 libimagentryutil: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer e553d20a8f libimagentrymarkdown: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer ebe2a9a110 libimagentryview: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 9b48dc27cd libimagentryref: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 5a7def4c8e libimagentryedit: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 7f04eb2bff libimagentrygps: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 0cbc6741a7 libimagentrytag: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 32e8c43ccb libimagentrylink: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 7357f1c985 libimagentryannotation: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer a8daeb851d libimagentrycategory: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 49ec0702fd libimagentryfilter: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 8236e73402 libimagrt: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 09e8619cf5 libimagstore: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer cc503920d0 libimaginteraction: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 5627bbe454 libimagnotification: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer 72add24d87 libimagutil: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer c2f674cc29 libimagerror: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-30 18:46:28 +01:00
Matthias Beyer c160a967ec Add error kinds 2018-10-30 18:46:28 +01:00
Matthias Beyer 22c13fed42 Fix: `--debug` on CLI should enable logging and override it
When specifying the `--debug` flag on the commandline, logging was not
enabled. That was because the config file parsing did not consider the
args.

Now, if `--debug` is passed on the CLI, logging is enabled for all
modules and level is set to `debug` for all modules.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-26 15:41:00 +02:00
Matthias Beyer 8ec8b0aca7 Hotfix: Ignore code snippet here 2018-10-24 23:46:21 +02:00
Matthias Beyer d87ea7b305 Add StoreId::local_display_string() function
for safely creating a `String` object from `StoreId` which can be shown
to the user.

Mainly introduced because this is useful for error handling (when
putting a `StoreId` into an error kind, the compiler complains that
`StoreId` does not meet the required trait bounds. But `String` does and
we do not process the ID any further anyways).

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-13 11:52:16 +02:00
Matthias Beyer 3090a65446 Add detailed comments on how the logger works 2018-10-11 00:15:48 +02:00
Matthias Beyer cc11162dd4 Fix: In-Memory filesystem backend did not remove on rename
The implementation of the in-memory filesystem for testing imag code did
not actually use `HashMap::remove()` when an entry was moved, but
`HashMap::get().cloned()`, which caused the original entry to exist
_after_ the move.

I'm not sure why this did not fail much earlier, but it was clearly
wrong. This commit adjust the test to check the "filesystem" before
checking the store and fixes the bug.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-09 17:37:56 +02:00
Matthias Beyer 388632d7ff Fix: Do not pass --rtp in testing environment
As we run tests in-memory (already for a rather long time), we don't
need to pass this anymore.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-09 17:37:56 +02:00
Matthias Beyer 6751c34f1b Fix: Remove call to deprecated function
This actually caused tests to fail if there was indeed a file at
/tmp/store/test and the test tried to create a "test" entry in the store.

Do use backend instead to check whether entry actually exists.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-09 17:37:35 +02:00
Matthias Beyer a0730c0ca9 Roll back mdcat update
Because 0.8 -> 0.10 has changed the API, we cannot update trivially.
Revert the update because of that.
2018-10-06 12:22:15 +02:00
Matthias Beyer 1161562372 Remove handlebars exception in log implementation
The issue was that the handlebars implementation logs as well and if we
use handlebars in the logger implementation that causes recursion which
crashes the program.

With handlebars 1.0.5, there is a feature[0] to disable logging in
handlebars (compiletime) which we use with this patch. The
exception-checking in the log implementation can be removed therefore.

[0]: https://github.com/sunng87/handlebars-rust/pull/236#issuecomment-427014611

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-10-06 12:22:15 +02:00