Feature request: :filter => lambda {|arg| arg.whatever } #225

shaiguitar opened this Issue Mar 26, 2012 · 3 comments


None yet

2 participants


Or something similar, basically a way to manipulate the command line argument that is passed in.

So for example something like this:

class FilterTaskArgScript < Thor

  default_task :output_symbol
  desc "output_symbol", "say option in lower case"

  method_option :baz, :type => :string, :alias => %w(-b),  :filter => lambda {|arg| arg.downcase.to_sym }

  def output_symbol
    puts options["baz"]

That would ensure that if you ran the task, the argument passed would be a downcase symbol.

$ thor filter_task_arg_script:output_symbol  # say option in lower case
$ thor filter_task_arg_script:output_symbol --baz SYMBOLIZE_ME
# ...
# would return :symbolize_me
# ...

Unless something like this exists which I'm not aware of?


What's the use case for this that doesn't work to do it inside the task itself?


I feel like something like that is more appropriate in the method_option line since that's where the arg is getting passed in, I want to manipulate it, bam, done. It's not a show-stopper by any means, just nice to have.


I get what you're saying. I think the way I'd do this is to have custom types (e.g. MethodName that might be a custom class that knows how to parse stuff). I know that's more work, but it'd be a cool thing to add if... you know.. you were interested ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment