Closed KINGSABRI closed 3 years ago
Each subcommand can have flags—everything nests. See the wiki article and let me know if that helps.
@davetron5000 thanks for the reply I've checked the wiki. The wiki explains subcommand and sub-subcommand and subcommand's switches and flag.
However, what I'm looking for is having a flag/switch has commands, these commands have flags/switches
Can a flag take a block to contain commands as command takes blocks?
This is a known example for a command has flags and switches
desc 'Describe list here'
arg_name 'Describe arguments to list here'
command :list do |c|
c.desc 'Describe a switch to list'
c.switch :s
c.desc 'Describe a flag to list'
c.default_value 'default'
c.flag :f
c.action do |global_options,options,args|
puts "list command ran"
end
end
but I looking to warp the above code in a flag/switch
desc 'module do good things'
arg_name 'module'
flag [:m,:module] do |f|
f.desc 'Describe the command of module flag here'
f.arg_name 'MODULENAME'
f.command :bruteforce do |c|
c.action do |global_options,options,args|
puts "bruteforcig......"
end
end
end
I'm not sure what you are wanting to do—do you want to execute code whenever someone uses a flag? If so, you can do that by checking the flag in the command's action
block.
In general, GLI is based on having flags/switches set options for the command and not to instigate actions themselves.
Closing as old and I think not an issue? Please reopen if you have more info
Hello guys How to create a sub-command for a flag, the subcommand might have command, flags and switches as well