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: exit command #4

Merged
merged 4 commits into from
Jul 30, 2022
Merged

feat: exit command #4

merged 4 commits into from
Jul 30, 2022

Conversation

pocketken
Copy link
Contributor

@pocketken pocketken commented Jul 28, 2022

I just wanted to say this is a great little project, thanks for contributing it! It's coming in quite handy for a little project I am working on for migrating from go-task.

I came across a bug while trying to use cd -- it assumes that all paths are relative to the CWD, which obviously leads to some weird behaviour when you do feed it absolute paths. I just added a quick check to leave absolute paths alone if provided, and that seems to do the trick.

I also needed exit and various incantations of test for my use case, so I added them as well. I know its a new project and that you're planning on adding support for more of the commands within deno_task_shell at some point, so maybe these aren't exactly what you're looking for.. but they fit the bill for my use case, so I thought I might as well PR them back as well just in case anyone else needs them in the meantime.

I apologize for being lazy and not adding tests; I just kind of made sure it worked for what I needed. I am ok with adding some tests as well if you'd like, but it may take me a couple of days.

Thanks again for the cool project!

Copy link
Owner

@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.

Thanks for this @pocketken! Yeah I'd rather land all this with tests so we don't break anything in the future. That said, if this PR was broken up into three separate PRs (one for the cd bug fix, one for test, and one for exit), then we can merge a few things faster than others and I can help get some tests in (just let me know where you'd like help).


export function exitCommand(args: string[]): ExitExecuteResult {
const code = parseInt(args[0], 10);
if (isNaN(code)) throw new Error("invalid result code");
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of throwing, we should probably log this message to stderr (, stderr: ShellPipeWriter) then return the same exit code that the exit command does in this scenario (I think 1, but my wsl is broken at the moment so I can't easily check).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like 2:

#!/bin/bash
exit aksjdksaj
$ bash ./t.sh
./t.sh: line 2: exit: aksjdksaj: numeric argument required
$ printf '%d\n' $?
2

src/common.ts Outdated
@@ -57,3 +59,9 @@ export function filterEmptyRecordValues<TValue>(record: Record<string, TValue |
}
return result;
}

export function resolvePath(cwd: string, arg: string) {
return path.isAbsolute(arg)
Copy link
Owner

Choose a reason for hiding this comment

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

Oh, I just assumed path.join handled this by default. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem. I also hoped that cd would take care of ~ and I was tempted to also include that in here -- but I was not sure if you wanted to add the dependency on std/node/os or not, so I handled it on my side. Are you open to the idea for the cd PR?

Copy link
Owner

Choose a reason for hiding this comment

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

That would be good, but I think std/node/os requires an --unstable flag to work. We could just copy this function into this library: https://deno.land/std@0.149.0/node/os.ts?code#L161

import { ExitExecuteResult } from "../result.ts";

export function exitCommand(args: string[]): ExitExecuteResult {
const code = parseInt(args[0], 10);
Copy link
Owner

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK cool, will work from that for the tests as well. My Rust is (I won't say it.. its just too easy) rough, so, I'll let you know if I have any questions.

@pocketken
Copy link
Contributor Author

Thanks for this @pocketken! Yeah I'd rather land all this with tests so we don't break anything in the future. That said, if this PR was broken up into three separate PRs (one for the cd bug fix, one for test, and one for exit), then we can merge a few things faster than others and I can help get some tests in.

Sure, no problem. Give me a few and I'll at least get the cd bugfix broken out right away. I'll also move the test one out, and we'll just use this one for exit given you've already provided some feedback I can address.

@pocketken pocketken changed the title cd bug fix; add test and exit commands feat: exit command Jul 29, 2022
@pocketken pocketken requested a review from dsherret July 29, 2022 17:05
@pocketken
Copy link
Contributor Author

@dsherret cd split out, test removed and exit updated as per original PR review comments. Hopefully this is better!

Copy link
Owner

@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.

Perfect! Thanks

@dsherret dsherret merged commit a937df9 into dsherret:main Jul 30, 2022
@pocketken pocketken deleted the dev/km/raptor branch July 30, 2022 21:30
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

2 participants