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

sh support #1

Open
sloanlance opened this issue Jan 22, 2019 · 1 comment
Open

sh support #1

sloanlance opened this issue Jan 22, 2019 · 1 comment
Assignees

Comments

@sloanlance
Copy link
Owner

sloanlance commented Jan 22, 2019

See the sh-support branch for code from user haochenx that adds support for shell I/O. Also see: https://stackoverflow.com/a/53273617/543738

Needs documentation and tests before opening a PR to upstream.

The qsh commands are meant to be "quiet" versions while the sh ones are verbose. I would change those around. sh should be quiet. qsh might be confused for a shell called "qsh", so they should be renamed to sh_verbose or just add a verbose flag to the sh commands.

The four blocks of code in src/builtin.c are very repetitive and need to be reduced. See:

jq/src/builtin.c

Lines 1565 to 1603 in 21da66b

static jv f_sh_json(jq_state *jq, jv input, jv cmd) {
jv_free(input);
char *cmdstr = jq_sh_extract_cmdstr(cmd);
if ((cmdstr) == NULL) return ret_error(cmd, jv_string(JQ_SH_EXTRACT_CMDSTR_ERRMSG));
jv r = jq_sh(cmdstr, 0, 1);
jv_mem_free(cmdstr);
jv_free(cmd);
return r;
}
static jv f_sh_str(jq_state *jq, jv input, jv cmd) {
jv_free(input);
char *cmdstr = jq_sh_extract_cmdstr(cmd);
if ((cmdstr) == NULL) return ret_error(cmd, jv_string(JQ_SH_EXTRACT_CMDSTR_ERRMSG));
jv r = jq_sh(cmdstr, 1, 1);
jv_mem_free(cmdstr);
jv_free(cmd);
return r;
}
static jv f_qsh_json(jq_state *jq, jv input, jv cmd) {
jv_free(input);
char *cmdstr = jq_sh_extract_cmdstr(cmd);
if ((cmdstr) == NULL) return ret_error(cmd, jv_string(JQ_SH_EXTRACT_CMDSTR_ERRMSG));
jv r = jq_sh(cmdstr, 0, 0);
jv_mem_free(cmdstr);
jv_free(cmd);
return r;
}
static jv f_qsh_str(jq_state *jq, jv input, jv cmd) {
jv_free(input);
char *cmdstr = jq_sh_extract_cmdstr(cmd);
if ((cmdstr) == NULL) return ret_error(cmd, jv_string(JQ_SH_EXTRACT_CMDSTR_ERRMSG));
jv r = jq_sh(cmdstr, 1, 0);
jv_mem_free(cmdstr);
jv_free(cmd);
return r;
}

Also see upstream issues stedolan#147 and stedolan#1101.

@sloanlance sloanlance self-assigned this Jan 22, 2019
@beckyconning
Copy link

Incredibly exciting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants