diff --git a/doc/pages/scopes.asciidoc b/doc/pages/scopes.asciidoc index 02bb5470..c74a7c21 100644 --- a/doc/pages/scopes.asciidoc +++ b/doc/pages/scopes.asciidoc @@ -39,7 +39,9 @@ Scopes are named as follows: *local*:: A local scope is inserted by each *evaluate-commands* invocations for its duration. Nested *evaluate-commands* each inject a new - local scope whose parent is the previous local scope. + local scope whose parent is the previous local scope. User declared + commands defined with *define-command* also introduce a local scope + while executing. A local scope is intended for temporarily overwriting some scoped value, such as an option or an alias. diff --git a/src/commands.cc b/src/commands.cc index d8335664..373f3b5c 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1404,6 +1404,7 @@ void define_command(const ParametersParser& parser, Context& context, const Shel desc = ParameterDesc{ {}, ParameterDesc::Flags::SwitchesAsPositional, min, max }; cmd = [=](const ParametersParser& parser, Context& context, const ShellContext& sc) { + LocalScope local_scope{context}; CommandManager::instance().execute(commands, context, { params_to_shell(parser), sc.env_vars }); }; @@ -1412,6 +1413,7 @@ void define_command(const ParametersParser& parser, Context& context, const Shel { desc = ParameterDesc{ {}, ParameterDesc::Flags::SwitchesAsPositional, 0, 0 }; cmd = [=](const ParametersParser& parser, Context& context, const ShellContext& sc) { + LocalScope local_scope{context}; CommandManager::instance().execute(commands, context, { {}, sc.env_vars }); }; }