coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

Require = for --tmpdir in mktemp

Open tmccombs opened this issue 2 years ago • 8 comments

Fixes #3454

This implementation more closely matches the behavior of GNU mktemp. Specifically, if using the short-form -p, then DIR is required, and if using the long form --tmpdir then DIR is optional, but if provided, must use the --tmpdir=DIR form (not --tempdir DIR), so that there is no ambiguity with also passing a TEMPLATE.

The downside to this implementation is we are now introducing a new workaround for https://github.com/clap-rs/clap/issues/4702 where we use separate calls to .arg() for the short -p and the long --tmpdir, which results in a less than ideal output for --help.

tmccombs avatar Feb 11 '23 06:02 tmccombs

Cool! Did you see #4275 already? Is this an improvement over that PR?

tertsdiepraam avatar Feb 11 '23 08:02 tertsdiepraam

I didn't see that other PR. I'm doing a review of it now. Overall, it looks pretty similar.

tmccombs avatar Feb 12 '23 08:02 tmccombs

I commented the same on the other PR, but I like the approach here a bit better, as long it passes the same tests. So you could copy the tests from that PR (maybe with a co-author credit to @dmatos2012 in the commit).

tertsdiepraam avatar Feb 12 '23 14:02 tertsdiepraam

GNU testsuite comparison:

GNU test failed: tests/misc/timeout. tests/misc/timeout is passing on 'main'. Maybe you have to rebase?

github-actions[bot] avatar Feb 13 '23 08:02 github-actions[bot]

Hey @tmccombs @tertsdiepraam , yes I also think this PR is slightly cleaner with the override_with() clap argument, and mine is for sure older, so fine by me to use this one, but I would like indeed if the tests that I wrote I used that I get the co-author like @tertsdiepraam mentioned.

So good job, looking nice :)

dmatos2012 avatar Feb 13 '23 08:02 dmatos2012

I just see that you've also opened an issue at clap. If they want this functionality that's fine, but I don't think we need to push for this feature and complicate clap unnecessarily. For context, I've been working on a custom argument parser for uutils (see https://github.com/uutils/coreutils/issues/4254). This is what mktemp looks like in that parser: https://github.com/tertsdiepraam/uutils-args/blob/main/tests/coreutils/mktemp.rs

tertsdiepraam avatar Feb 13 '23 10:02 tertsdiepraam

Looks good! From my perspective, all that's missing is a co-author credit for @dmatos2012 in the test commit.

tertsdiepraam avatar Apr 02 '23 10:04 tertsdiepraam

Fails on Windows:

---- test_mktemp::test_both_tmpdir_flags_present stdout ----
run: D:\a\coreutils\coreutils\target\i686-pc-windows-msvc\debug\coreutils.exe mktemp -p . --tmpdir foobarXXXX
thread 'test_mktemp::test_both_tmpdir_flags_present' panicked at ''C:\Windows\foobarT7LG
' does not contain '/tmp/foobar'', tests\by-util\test_mktemp.rs:861:10
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library\std\src\panicking.rs:584
   1: core::panicking::panic_fmt
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library\core\src\panicking.rs:142
   2: tests::common::util::CmdResult::stdout_contains<str>
             at .\tests\common\util.rs:653
   3: tests::test_mktemp::test_both_tmpdir_flags_present
             at .\tests\by-util\test_mktemp.rs:853
   4: tests::test_mktemp::test_both_tmpdir_flags_present::closure$0
             at .\tests\by-util\test_mktemp.rs:851
   5: core::ops::function::FnOnce::call_once<tests::test_mktemp::test_both_tmpdir_flags_present::closure_env$0,tuple$<> >
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52\library\core\src\ops\function.rs:248
   6: core::ops::function::FnOnce::call_once
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library\core\src\ops\function.rs:248
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    test_mktemp::test_both_tmpdir_flags_present

sylvestre avatar Apr 03 '23 08:04 sylvestre

GNU testsuite comparison:

Skip an intermittent issue tests/tail-2/inotify-dir-recreate

github-actions[bot] avatar Jun 22 '23 07:06 github-actions[bot]

I'm trying to fix the test on windows to get this merged finally :)

tertsdiepraam avatar Jul 05 '23 10:07 tertsdiepraam

GNU testsuite comparison:

Skip an intermittent issue tests/rm/rm1
GNU test failed: tests/rm/rm2. tests/rm/rm2 is passing on 'main'. Maybe you have to rebase?

github-actions[bot] avatar Jul 05 '23 12:07 github-actions[bot]

well done!

sylvestre avatar Jul 21 '23 12:07 sylvestre