Skip to content

Head command, plus fix for cat #49

Merged
merged 6 commits into from

3 participants

@legien
Collaborator

No description provided.

legien added some commits
@legien legien Adds head command. 0843243
@legien legien Merge remote-tracking branch 'original/master' 5853755
@legien legien Modified cat and head for better 'pipeability'.
1436d5b
@legien legien Merge remote-tracking branch 'original/master'
53489cc
@legien legien Removed second cat.
e60b7ab
@nfischer
Collaborator

You could also expose head as its own package, I think.

@nfischer nfischer commented on the diff
dist/commands/head.js
+'use strict';
+
+var interfacer = require('./../util/interfacer');
+var fs = require('fs');
+var fsAutocomplete = require('vorpal-autocomplete-fs');
+
+var head = {
+ exec: function exec(args, options) {
+ var self = this;
+ options = options || {};
+
+ options.argsType = args.stdin === undefined ? 'files' : 'stdin';
+ options.n = options.n === undefined ? 10 : options.n;
+
+ if (options.n < 1) {
+ self.log('Option n must be a positive integer.');
@nfischer
Collaborator
nfischer added a note

Linux head actually takes a negative argument as well. head -n -1 means "output the all the lines of the file, except the last line," -n -3 means "all the lines except for the last 3 lines," etc.

Also, -n 0 also works, it just outputs nothing, with status 0 (only if it can read the file, otherwise it fails).

@legien
Collaborator
legien added a note

@nfischer Head | IEEE 1003.1

The head utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.

The following option shall be supported:

-n number
The first number lines of each input file shall be copied to standard output. The application shall ensure that the number option-argument is a positive decimal integer.
When a file contains less than number lines, it shall be copied to standard output in its entirety. This shall not be an error.

If no options are specified, head shall act as if -n 10 had been specified.

I see your point here, but to be posix compliant we need to make sure it is a positive decimal integer. I'm not sure about the 0. Is 0 a positive decimal integer?

@nfischer
Collaborator
nfischer added a note

I see your point. I think supporting negative options wouldn't necessarily be a bad move, but it seems like it's not necessary according to this standard.

I believe 0 is not a positive integer. So it's up to you if you want to support it or not, just like with negative values :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dthree
Owner

@legien just reviewed this and it looks great!

Can you please rebase this really quickly? I merged some other PRs and there's some unrelated conflicts including the latest version of Vorpal. Right after this, I can merge.

Thanks.

@legien legien Merge remote-tracking branch 'original/master'
c6cb356
@legien
Collaborator

@dthree you're welcome.

@dthree dthree merged commit b9f9ee9 into dthree:master

2 checks passed

Details continuous-integration/appveyor/pr AppVeyor build succeeded
Details continuous-integration/travis-ci/pr The Travis CI build passed
@dthree
Owner

@legien you're the best! :fire: :star2: :+1:

@dthree
Owner

Head is published in v0.7.0!

b0be128


Added you to the readme as well, and published cash-head as an individual package. Thanks again!


Question: I'm looking for serious collaborators to help push Cash forward. Are you interested in this?

@legien
Collaborator

Sure. :+1:

@nfischer
Collaborator

@dthree I can also help out with the simple commands and bash-related things, and reviewing for compatibility with the standard utilities.

@dthree
Owner

Okay,you guys are awesome! :+1:

Added you both as collaborators. Until you get a bit more familiar with the project, please ping me on changes you do. Feel free to make minor patches, obviously on anything breaking consult with me as well.

:star2:

@nfischer
Collaborator

SGTM :+1: I think I'll hold off on merging things for now, and just give LGTM on PRs that look good, and let you (@dthree) handle merging.

@dthree
Owner

Kk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.