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

feat: add basic head command #93

Merged
merged 2 commits into from
Oct 27, 2023
Merged

feat: add basic head command #93

merged 2 commits into from
Oct 27, 2023

Conversation

dahlia
Copy link
Contributor

@dahlia dahlia commented Sep 11, 2023

This patch partially addresses issue #92. It implements the very basic head command, with the following limitations:

  • It can accept at most one file.
  • The only options it supports are -n/--lines.
  • The -n/--lines option cannot accept negative numbers.

@CLAassistant
Copy link

CLAassistant commented Sep 11, 2023

CLA assistant check
All committers have signed the CLA.

@dsherret dsherret changed the title Add basic head command feat: add basic head command Sep 18, 2023
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for this! I just have a few questions.

writer.write_all(b"\n")?;
lines += 1;
} else {
writer.write_all(&buf)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to write only the size of the buffer and not the entire buffer which might contain data from a previous read at the end? We should extract out this function and add a unit test that triggers this scenario.

let size = read(&mut buf)?;
if size == 0 {
break;
} else if let Some(line) = buf.split(|&b| b == b'\n').next() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to the rest of the lines in the buffer? I'm not sure how the tests work so I must be reading this wrong.

This patch partially addresses issue denoland#92.  It implements the very basic
`head` command, with the following limitations:

- It can accept at most one file.
- The only options it supports are `-n`/`--lines`.
- The `-n`/`--lines` option cannot accept negative numbers.
@dahlia
Copy link
Contributor Author

dahlia commented Sep 21, 2023

@dsherret As you pointed out in your review, there were actually a bunch of bugs in copy_lines(), so I extracted it out to the module level and added unit tests for it to fix them. Could you take another look at this?

@dahlia
Copy link
Contributor Author

dahlia commented Oct 4, 2023

Would there be anything left for me to fix?

@dsherret
Copy link
Member

dsherret commented Oct 4, 2023

@dahlia no, thanks! I just need to find the time to review the actual functionality. I'll get this in for Deno 1.38 which will be released in I think a month.

@dahlia
Copy link
Contributor Author

dahlia commented Oct 4, 2023

Thanks, I'm looking forward to it!

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @dahlia!

@dsherret dsherret merged commit 279f6e2 into denoland:main Oct 27, 2023
4 checks passed
@dahlia
Copy link
Contributor Author

dahlia commented Oct 27, 2023

Thank you!

dsherret added a commit to denoland/deno that referenced this pull request Oct 28, 2023
Adds a built-in `head` command to deno task:

denoland/deno_task_shell#93
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

Successfully merging this pull request may close these issues.

None yet

3 participants