Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8309063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:59:44+00:00 2026-06-08T18:59:44+00:00

This is Thor task: desc ‘readkeys’, ‘Read keys’ method_option :password, :type => :string, :desc

  • 0

This is Thor task:

  desc 'readkeys', 'Read keys'
  method_option :password, :type => :string, :desc => 'Password for the key store'
  def readkeys
    if options[:password].nil?
      puts "Enter keystore password"
      options[:password] = gets
    end

    File.open("#{Dir.home}#{File::SEPARATOR}#{ENV['USER']}.p12") do |p12|
      pkcs12 = OpenSSL::PKCS12.new(p12.read, options[:password])
    end
  end

When I run the command, I get this error:

./mycommand:26:in `gets’: No such file or directory – readkeys
(Errno::ENOENT)

Any ideas? The syntax seems fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:59:45+00:00Added an answer on June 8, 2026 at 6:59 pm

    Two issues I see in this. The first is that you can’t actually modify the options hash from Thor. It’s frozen, and you’ll get a `[]=': can't modify frozen Thor::CoreExt::HashWithIndifferentAccess (RuntimeError).

    The real issue, though, is that you’re working at too low a level. What you’re looking for is the ask method of Thor::Actions. If I understand your code properly, to do what you want to do you’d do something like this:

    class Test < Thor   
      include Thor::Actions
    
      desc 'readkeys', 'Read keys'
      method_option :password, :type => :string, :desc => 'Password for the key store'
      def readkeys
        if options[:password].nil?
          password = ask "Enter keystore password"
        else
          password = options[:password]
        end
        File.open("#{Dir.home}#{File::SEPARATOR}#{ENV['USER']}.p12") do |p12|
          pkcs12 = OpenSSL::PKCS12.new(p12.read, password)
        end
      end
      #...
    end
    

    Or, more simply,

    class Test < Thor   
      include Thor::Actions
    
      desc 'readkeys', 'Read keys'
      method_option :password, :type => :string, :desc => 'Password for the key store'
      def readkeys
        password = options[:password] || ask("Enter keystore password")
        File.open("#{Dir.home}#{File::SEPARATOR}#{ENV['USER']}.p12") do |p12|
          pkcs12 = OpenSSL::PKCS12.new(p12.read, password)
        end
      end
      #...
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using thor I am used to writing code like this, desc import, Import
This is my code: <CheckBox android:id=@+id/sprint_checkbox android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/sprint_game /> <CheckBox android:id=@+id/marathon_checkbox android:layout_width=fill_parent android:layout_height=wrap_content
This is the file auth.txt (username password) paolo 1234 luca 0000 marci 1000 And
I have a Thor script that uses several methods class Update < Thor desc
Am I right in saying that thor runs independently of rails? If this is
I would like to use the popular Thor gem to create a daemonized task.
I'm trying to figure out how the Thor gem creates a DSL like this
i want to create a command line tool in Ruby using Thor. This tool
I want to call a thor task from a Migration. With rake I can
Is it possible to call a specific task first, when i run a thor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.