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.
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
askmethod ofThor::Actions. If I understand your code properly, to do what you want to do you’d do something like this:Or, more simply,