-
Notifications
You must be signed in to change notification settings - Fork 1
Support line lengths without #172
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,9 +86,18 @@ import ( | |
|
|
||
| // Cmd is the tail builtin command descriptor. | ||
| var Cmd = builtins.Command{ | ||
| Name: "tail", | ||
| Description: "output the last part of files", | ||
| MakeFlags: registerFlags, | ||
| Name: "tail", | ||
| Description: "output the last part of files", | ||
| MakeFlags: registerFlags, | ||
| NormalizeArgs: normalizeArgs, | ||
| } | ||
|
|
||
| // normalizeArgs rewrites legacy -N shorthand (e.g. -5) to -n N so that | ||
| // pflag can parse it. Only a bare -<digits> token in the first argument | ||
| // position is rewritten, matching GNU tail behavior where the obsolete form | ||
| // is only accepted as the first option. | ||
| func normalizeArgs(args []string) []string { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth sharing
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call! Extracted the shared logic into
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol stupid gpt comment. I never would have said |
||
| return builtins.NormalizeBareNumberArg(args, []string{"-n", "-c", "--lines", "--bytes"}) | ||
| } | ||
|
|
||
| // MaxCount is the maximum accepted line or byte count. Values above this | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| description: head -3 (bare numeric shorthand) outputs the first 3 lines, equivalent to head -n 3. | ||
| setup: | ||
| files: | ||
| - path: file.txt | ||
| content: "alpha\nbeta\ngamma\ndelta\nepsilon\n" | ||
| input: | ||
| allowed_paths: ["$DIR"] | ||
| script: |+ | ||
| head -3 file.txt | ||
| expect: | ||
| stdout: "alpha\nbeta\ngamma\n" | ||
| stderr: "" | ||
| exit_code: 0 | ||
|
astuyve marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| description: head -42 works with larger bare numeric shorthand. | ||
| input: | ||
| script: |+ | ||
| printf "1\n2\n3\n" | head -42 | ||
| expect: | ||
| stdout: "1\n2\n3\n" | ||
| stderr: "" | ||
| exit_code: 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| description: head -5 works with piped input. | ||
| input: | ||
| script: |+ | ||
| printf "1\n2\n3\n4\n5\n6\n7\n" | head -5 | ||
| expect: | ||
| stdout: "1\n2\n3\n4\n5\n" | ||
| stderr: "" | ||
| exit_code: 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| description: head -0 (bare zero shorthand) produces no output, equivalent to head -n 0. | ||
| input: | ||
| script: |+ | ||
| printf "1\n2\n3\n" | head -0 | ||
| expect: | ||
| stdout: "" | ||
| stderr: "" | ||
| exit_code: 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| description: tail -3 (bare numeric shorthand) outputs the last 3 lines, equivalent to tail -n 3. | ||
| setup: | ||
| files: | ||
| - path: file.txt | ||
| content: "alpha\nbeta\ngamma\ndelta\nepsilon\n" | ||
| input: | ||
| allowed_paths: ["$DIR"] | ||
| script: |+ | ||
| tail -3 file.txt | ||
| expect: | ||
| stdout: "gamma\ndelta\nepsilon\n" | ||
| stderr: "" | ||
| exit_code: 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| description: tail -5 works with piped input. | ||
| input: | ||
| script: |+ | ||
| printf "1\n2\n3\n4\n5\n6\n7\n" | tail -5 | ||
| expect: | ||
| stdout: "3\n4\n5\n6\n7\n" | ||
| stderr: "" | ||
| exit_code: 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| description: tail -0 (bare zero shorthand) produces no output, equivalent to tail -n 0. | ||
| input: | ||
| script: |+ | ||
| printf "1\n2\n3\n" | tail -0 | ||
| expect: | ||
| stdout: "" | ||
| stderr: "" | ||
| exit_code: 0 |
Uh oh!
There was an error while loading. Please reload this page.