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

--argfile behavior #705

Closed
pkoppstein opened this issue Feb 19, 2015 · 8 comments
Closed

--argfile behavior #705

pkoppstein opened this issue Feb 19, 2015 · 8 comments
Labels
Milestone

Comments

@pkoppstein
Copy link
Contributor

The manual says:

--argfile name filename:

This option passes the first value from the named file as a value to the jq program

This however is inconsistent with the current behavior, which is (in a sense) itself inconsistent. If file a contains a string, then jq -n --argfile a a '$a' prints it out; but if it contains two strings, or is empty, the same program prints an array.

The current behavior is certainly justifiable, but maybe this is a good time to orthogonalize things a bit -- perhaps even to the point of giving the user the same control over each "argfile" as is afforded with respect to stdin. For example, we could have --argfile, --argfile-slurp, argfile-raw, ...

Food for thought? (No slurping, please.)

@nicowilliams
Copy link
Contributor

Yes, it does this: slurp the file, and if the thing is an array of just one element, it uses that, else it uses the slurped array. That's lame, I agree (yes, I wrote that code :). I'll make it just slurp.

@nicowilliams
Copy link
Contributor

@pkoppstein

$foo can't be bound to a stream. It has to be a value. So either --argfile slurps, or it only gives you the first value found (what if none are found? there would be no way to distinguish an empty file from a file that contains whatever value, probably null, we decide to use to denote "empty file").

I wouldn't be against --slurpfile, but I think having --argfile slurp is good enough.

@nicowilliams
Copy link
Contributor

Hmmm, this is a backwards-incompatible change. --argfile shipped as it was in 1.4.

@nicowilliams
Copy link
Contributor

I may have to revert this change.

@nicowilliams nicowilliams reopened this Feb 19, 2015
@nicowilliams nicowilliams added this to the 1.5 release milestone Feb 19, 2015
@pkoppstein
Copy link
Contributor Author

@nicowilliams wrote:

Hmmm

(1) The current behavior is inconsistent with the manual, so there is quite a lot of wriggle room here. Since p ^ ~p => q is true for all WFFs p and q. The important thing is that q be well-formed.

(2) The current specification of --argfile (if the manual can be read as a specification) has the advantage that it complements --slurpfile. The more orthogonality, the better.

(3) Please do not read (2) as a strong endorsement of the documented behavior: see (1).

(4) Having control on a file-by-file basis would be a Very Good Thing.

@nicowilliams
Copy link
Contributor

The way to distinguish what happened (slurped vs. not slurped) could be to add a second variable named after the given one.

@nicowilliams
Copy link
Contributor

I'll probably do that and revert the change I pushed earlier.

nicowilliams added a commit that referenced this issue Mar 24, 2015
@nicowilliams
Copy link
Contributor

I think I'll restore the original behavior and add a new argument with better behavior.

nicowilliams added a commit that referenced this issue May 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants