Filename arguments invalidated after implicit cd
CGamesPlay opened this issue · 0 comments
Hey, loving the activity on this project. Thanks for resolving #118 so quickly. I've now ported most of my projects to using argc, and I'm seeing how far I can push it.
It's great that argc automatically cds into the directory of the Argcfile.sh it finds in the parent hierarchy; this is generally the thing that a script author wants. However, if the command accepts a filename argument, the filename is invalid when the script gets run. See this Argcfile for an example:
#!/usr/bin/env bash
# @arg file <FILE>
set -e
eval "$(argc --argc-eval "$0" "$@")"
ls $argc_file
Run this script:
mkdir directory
cd directory
touch test.txt
argc test.txt
The script fails, because the file does not exist, because the directory was changed.
I can think of a few options here:
- Export
ARGC_ORIGINAL_PATH
or some other variable, which contains the path of the original pwd. - For <FILE/DIR/PATH> arguments, they are automatically prefixed with the appropriate path.
The first option seems like the best overall to me. The second requires that the argument values are tagged properly, and there could also be use cases where we don't need a specific argument, but we still want to know the original directory of the command.
Thanks for your consideration!