Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
shaiguitar opened this Issue · 3 comments

2 participants

@shaiguitar

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"]
    options["baz"]
  end
end

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?

@eventualbuddha
Collaborator

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

@shaiguitar

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.

@eventualbuddha
Collaborator

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
Something went wrong with that request. Please try again.