diff options
author | Muh Muhten <muh.muhten@gmail.com> | 2017-10-15 01:57:17 -0400 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2019-02-20 19:16:18 -0600 |
commit | 450ade4818ed604c3a2b7966d22004980b856d57 (patch) | |
tree | 7cdfee55443c2c3373753e8582ec0d08d57cc2ab /src | |
parent | c814c4e001d1f6961f3bc81f7c50f551f1d2c939 (diff) |
Add import metadata key "optional"
A library marked is imported if found, but silently skipped if missing.
This is the desired semantic for the auto-include at ~/.jq
Diffstat (limited to 'src')
-rw-r--r-- | src/linker.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/linker.c b/src/linker.c index 792b858e..0b855d5f 100644 --- a/src/linker.c +++ b/src/linker.c @@ -246,6 +246,9 @@ static int process_dependencies(jq_state *jq, jv jq_origin, jv lib_origin, block jv v = jv_object_get(jv_copy(dep), jv_string("raw")); if (jv_get_kind(v) == JV_KIND_TRUE) raw = 1; + int optional = 0; + if (jv_get_kind(jv_object_get(jv_copy(dep), jv_string("optional"))) == JV_KIND_TRUE) + optional = 1; jv_free(v); jv relpath = validate_relpath(jv_object_get(jv_copy(dep), jv_string("relpath"))); jv as = jv_object_get(jv_copy(dep), jv_string("as")); @@ -259,10 +262,14 @@ static int process_dependencies(jq_state *jq, jv jq_origin, jv lib_origin, block jv resolved = find_lib(jq, relpath, search, is_data ? ".json" : ".jq", jv_copy(jq_origin), jv_copy(lib_origin)); // XXX ...move the rest of this into a callback. if (!jv_is_valid(resolved)) { + jv_free(as); + if (optional) { + jv_free(resolved); + continue; + } jv emsg = jv_invalid_get_msg(resolved); jq_report_error(jq, jv_string_fmt("jq: error: %s\n",jv_string_value(emsg))); jv_free(emsg); - jv_free(as); jv_free(deps); jv_free(jq_origin); jv_free(lib_origin); |