Closed np422 closed 3 years ago
You could mimic this by using the passed command
object in the pre
. It has a parent
attribute which is either the parent command or the GLI App if the command is a top level subcommand, so you could do something like:
def find_top_level_command(command)
if command.parent.kind_of?(GLI::Command)
find_top_level_command(command.parent)
else
command
end
end
pre do |global,command,options,args|
top_level_command = find_top_level_command(command)
if top_level_command.name == "foo"
# do whatever common stuff is needed for "foo" commands
end
end
Hack-ish, but would work.
Thank you! This gets the job done!
I'm working on a an app with a lot of subcommands.
It would be great if a pre block could be specified inside a command to define a pre-block that is executed for all subcommands of that command.