diff --git a/doc_src/cmds/argparse.rst b/doc_src/cmds/argparse.rst index 393a32e70..fd8f0c64d 100644 --- a/doc_src/cmds/argparse.rst +++ b/doc_src/cmds/argparse.rst @@ -114,7 +114,7 @@ Sometimes you need to validate the option values. For example, that it is a vali - ``_flag_value`` will be set to the value associated with the flag being processed. -If you do this via a function it should be defined with the ``--no-scope-shadowing`` flag. Otherwise it won't have access to those variables. +These variables are passed to the function as local exported variables. The script should write any error messages to stdout, not stderr. It should return a status of zero if the flag value is valid otherwise a non-zero status to indicate it is invalid. diff --git a/src/builtin_argparse.cpp b/src/builtin_argparse.cpp index 58e941d63..4677d2076 100644 --- a/src/builtin_argparse.cpp +++ b/src/builtin_argparse.cpp @@ -457,13 +457,13 @@ static int validate_arg(parser_t &parser, const argparse_cmd_opts_t &opts, optio auto &vars = parser.vars(); vars.push(true); - vars.set_one(L"_argparse_cmd", ENV_LOCAL, opts.name); + vars.set_one(L"_argparse_cmd", ENV_LOCAL | ENV_EXPORT, opts.name); if (is_long_flag) { - vars.set_one(var_name_prefix + L"name", ENV_LOCAL, opt_spec->long_flag); + vars.set_one(var_name_prefix + L"name", ENV_LOCAL | ENV_EXPORT, opt_spec->long_flag); } else { - vars.set_one(var_name_prefix + L"name", ENV_LOCAL, wcstring(1, opt_spec->short_flag)); + vars.set_one(var_name_prefix + L"name", ENV_LOCAL | ENV_EXPORT, wcstring(1, opt_spec->short_flag)); } - vars.set_one(var_name_prefix + L"value", ENV_LOCAL, woptarg); + vars.set_one(var_name_prefix + L"value", ENV_LOCAL | ENV_EXPORT, woptarg); int retval = exec_subshell(opt_spec->validation_command, parser, cmd_output, false); for (const auto &output : cmd_output) {