You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
since the --list switch belongs to module1 not to cooltool
here's my initial dirty implementation
cooltool.rb
require'trollop'require'pp'moduleCoolToolclassOptionParserattr_reader:main_optsdefinitialize@main_opts=Trollop::optionsdobanner"Cool tool."banner"Options:"opt:parse,"Parse a string",:short=>:p,:type=>:stringopt:module,"Use module",:short=>:m,:default=>''endenddefmodules_list@modules_list=%w(module1module2module3)endendendopts=CoolTool::OptionParser.newcasewhenopts.main_opts[:parse]puts"Parsing!!"whenopts.main_opts[:module]mod=opts.main_opts[:module]require"./#{mod}.rb"ppCoolTool::CoolToolModule.const_get(mod.capitalize).newelseputsopts.main_optsend
module1.rb
moduleCoolToolmoduleCoolToolModuleclassModule1attr_accessor:optsdefinitialize@opts=Trollop::Parser.newdobanner"Module1."banner"Options:"opt:list,"The user list.",:short=>:l,:type=>:stringend@opts.parseARGVend# make module read the file if -l user.txtdefrunif@opts[:list]File.readlines(@opts[:list])elseputs'Some Error'endendendendend
I need each module to have its own commands and/or switches. Those modules called by --module/-m switch. The problem is, when I use --list switch trollop sees it as an argument for cooltool since its cooltool's stdin
This is already handled using Commands. However, commands don't use a literal switch. You might be able to use a switch in a manner similar to the example, but I'm not sure. If you don't really need the switch, see if you can get it to work like the example.
Hello there,
I've requirements here that I hope I explain it well.
here is the case I'm trying to do
since the
--list
switch belongs tomodule1
not tocooltool
here's my initial dirty implementation
cooltool.rb
module1.rb
I need each module to have its own commands and/or switches. Those modules called by
--module/-m
switch. The problem is, when I use--list
switch trollop sees it as an argument for cooltool since its cooltool's stdinThanks
The text was updated successfully, but these errors were encountered: