I'm unhappy about how to keep active some "global" flags when using subcommands
This is an example where a --verbose flag is setup on top of every subcommands:
require "admiral"
module Log
class_property verbose = false
end
class HelloWorld < Admiral::Command
def run
Log.verbose = self.flags.verbose
puts "Hello World"
end
class SubCommand < Admiral::Command
def run
Log.verbose = self.parent.as(HelloWorld).flags.verbose
puts "SubCommand"
end
end
define_flag verbose : Bool, default: false, short: v
register_sub_command sub_command, type: SubCommand
end
HelloWorld.run
My main problem is I need to repeat the code Log.verbose = self.parent.as(HelloWorld).flags.verbose on every run for each subcommands or the flag will be ignored.
Would it be great if we can put a block on define_flag like this:
Hello,
I'm unhappy about how to keep active some "global" flags when using subcommands
This is an example where a
--verbose
flag is setup on top of every subcommands:My main problem is I need to repeat the code
Log.verbose = self.parent.as(HelloWorld).flags.verbose
on everyrun
for each subcommands or the flag will be ignored.Would it be great if we can put a block on
define_flag
like this:This code would be triggered even if
run
of the command is not called due to subcommand