Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions to work with filesystem paths: expand_path , get_home, get_abspath #3057

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,26 @@ static jv f_env(jq_state *jq, jv input) {
return env;
}

static jv f_expand_path(jq_state *jq, jv input) {
if (jv_get_kind(input) != JV_KIND_STRING) {
return type_error(input, "expand_path/0: string required");
}
return expand_path(input);
}

static jv f_get_home(jq_state *jq, jv input) {
jv_free(input);
return get_home();
}

static jv f_get_abspath(jq_state *jq, jv input) {
if (jv_get_kind(input) != JV_KIND_STRING) {
return type_error(input, "get_abspath/0: string required");
}
return jq_realpath(input);
}


static jv f_halt(jq_state *jq, jv input) {
jv_free(input);
jq_halt(jq, jv_invalid(), jv_invalid());
Expand Down Expand Up @@ -1738,6 +1758,9 @@ BINOPS
{f_error, "error", 1},
{f_format, "format", 2},
{f_env, "env", 1},
{f_expand_path, "expand_path", 1},
{f_get_home, "get_home", 1},
{f_get_abspath, "get_abspath", 1},
{f_halt, "halt", 1},
{f_halt_error, "halt_error", 2},
{f_get_search_list, "get_search_list", 1},
Expand Down