Questions tagged [thor]
Thor is a scripting framework that replaces Rake, Sake and RubiGen.
231
questions
0
votes
1
answer
12
views
Aliases for limited_options in Thor
I want to ask the user for input in Thor but have aliases:
$ Is this correct?: [yes, no, maybe] (yes)
Currently I have this:
class CLI < Thor
desc 'do_thing', 'does a thing'
def do_thing
...
0
votes
0
answers
28
views
Thor third level subcommand not represented correctly in output
I am having an issues in thor 1.2.1 where the 3rd level command isn't representing the help correctly. Here is some demo code:
#! /usr/bin/env ruby
require "thor"
module SubCommand2
...
-1
votes
1
answer
73
views
Why is an outdated version of a Ruby script used when running Ruby from a Subprocess in Python?
I'm trying to run a Ruby project from a Python interface, but in its most current form it only works when run from a terminal, not from a Subprocess in Python. The Ruby project consists of an ...
2
votes
1
answer
224
views
How to copy directory of *.tt files with thor?
Is it possible to copy a directory of *.tt files without executing template engine. I'd like to improve my rails templates and add custom scaffold templates (views, controllers and specs), but every ...
0
votes
0
answers
47
views
Thor commandline interface running in Ruby gem test environment but not from command line
After following this tutorial I decided to use Aruba, Cucumber and Thor to add CLI functionality for a gem that I'm working on. When I run bundle exec cucumber features
all of my test are green. Here ...
0
votes
1
answer
147
views
Rails new command fails if -m template is applied: "NoMethodError: private method `open' called for URI:Module"
I have been bumping into this issue and could not find a way to fix it.
When I am creating new rails apps using templates, the generator fails on private method 'open' called for URI:Module (...
1
vote
1
answer
397
views
Using ksdiff as THOR_MERGE tool in zshell
I'm trying to run the rails update script with the following in my .zshrc file (for use in merge conflicts):
export THOR_MERGE="/usr/local/bin/ksdiff --merge --output $MERGED -- $LOCAL $REMOTE&...
1
vote
0
answers
40
views
Thor gem copying an empty directory isn't working
from the doc: https://rdoc.info/github/erikhuda/thor/master/Thor%2FActions:directory
#directory(source, *args, &block)
... If any empty directory is found, it's copied and all .empty_directory ...
2
votes
0
answers
360
views
how to generate a migration with custom generator
this is my generator class in lib/genrators/form
class FormGenerator < Rails::Generators::Base
source_root File.expand_path('templates', __FILE__)
source_root File.expand_path('...
2
votes
2
answers
560
views
Creating nested subcommands using Thor
I'd like to create a CLI tool which has commands in a format something like this:
clitool jobs execute some-job --arg1 value --arg2 another_value
Is it possible to have a subcommand of a subcommand ...
1
vote
0
answers
83
views
How to get an organizational structure of commands, subcommands, options of a Ruby class that inherits from Thor?
I'm trying to implement an autocomplete feature for a CLI that inherits from Thor.
Right now I have a bash script written that has hard-coded autocompletions based on the previous word. For example
~ ...
0
votes
1
answer
408
views
Is there a way to add hooks to a Thor class in order to run code before/after all commands?
I'm working on a CLI tool powered by the Thor gem. Say I have a Cli class that inherits from Thor, which defines a CLI tool that has a few commands associated with it:
class Cli < Thor
def ...
4
votes
1
answer
166
views
Fixing Rails generator issues: calling same generator twice no-ops and exits 0 without running 2nd generator
We are on Rails 5 and have a flow we are trying to automate which involves the creation of several models. We made a custom generator that handles this, among other things.
The first step creates ...
0
votes
0
answers
149
views
Middleman Permission denied while installing thor (0.20.3), and Bundler cannot continue
I haven't touched my Middleman App for a few months and now it doesn't work.
It seems like some dependencies are broken and that a gem is blocking everything.
Errno::EACCES: Permission denied @ ...
0
votes
1
answer
171
views
thor::Animator playing only one frame
I've been trying to animate an sf::Sprite with Thor 2.1, but as of now my sprite only displays one frame of each animation, not going through all of them.
I've got a sample spritesheet out of one of ...
0
votes
1
answer
676
views
How can I mock a Ruby "require" statement in RSpec?
I have a Ruby cli program that can optionally load a user-specified file via require. I would like to unit test this functionality via RSpec. The obvious thing to do is to mock the require and ...
2
votes
1
answer
244
views
Using class_name in a custom Rails generator
I have a basic custom generator that looks like this, that inherits from Rails::Generators::NamedBase in a Rails 5.1 app
class NotificationGenerator < Rails::Generators::NamedBase
source_root ...
1
vote
1
answer
130
views
How can I pass a switch before the command in a Thor app?
I have a Thor app that requires many of the same parameters for all the commands. The universal parameters are declared with class_option. But I want users to put those before the command.
For ...
2
votes
1
answer
1k
views
Testing a Thor script with rspec and vcr
I built a Thor script that connects to an HTTP API to perform some very simple actions. I've coded tests for the backend but the Thor script is basically untested, which is quite suboptimal.
My first ...
0
votes
1
answer
188
views
Make Thor show message for top level command
Is there any way to make Thor show a general message for the top level command?
$my_command help
I'd like to show a welcome message here.
Commands:
my_command help [COMMAND]
1
vote
0
answers
169
views
Ruby YARD: skip to next method definition when building source view
Is there a way to skip to the next def keyword in yard when building the source view?
Usecase
Say I'm writing a thor app. Ideally I'd document it like this:
require 'thor'
class Foo < Thor
##
...
2
votes
4
answers
897
views
Rails returns error when I try to create a new project
Rails broke on my system and now whenever I run rails new my_app it gives me a weird Thor error.
joshuahadik -> rails new hello_world
Traceback (most recent call last):
21: from /Users/...
1
vote
0
answers
46
views
View changes in custom Rails generator
I'd like to view the affected files and/or changes that will be made prior to running a method in my custom Rails generator. I've looked through the docs for days and am beginning to think its not ...
0
votes
1
answer
173
views
undefined method `find_each' for Thor::Group:Class
I have written a Thor task that's supposed to iterate through all Users leveraging find_each. But I get this error message:
undefined method find_each for Thor::Group:Class`
Why isn't find_each ...
-1
votes
1
answer
71
views
Ruby : Simple Calculator using THOR to provide values at terminal. Error:`add': uninitialized constant MyCLI::Simplecal (NameError)
I have two "rb" files:
SimpleCal.rb,
cli.rb
SimpleCal.rb->Code
class SimpleCal
#adding two numbers
def addition_function(n1,n2)
n1 + n2
end
#subtracting two numbers (Validation:n2 shouldn'...
0
votes
1
answer
446
views
Ruby :undefined local variable or method `n1' (NameError)
I am a newbie in ruby. I am inheriting thor gem within my class. The class should perform the task of adding two numbers.
Code:
require 'thor'
class MyCLI < Thor
desc "add", "Addition of two ...
0
votes
1
answer
278
views
How do I stub method_options using Rspec?
Class CLI < Thor
desc "run [age]" "user passes age"
method_option :age,type:'numeric'
def run
variable=options[:a] if options[:a].present?
call_method(a)
end
end
...
0
votes
1
answer
511
views
Create a CLI with Thor for a gem
I'm creating a gem that gives the weather connecting to APIs, i also created tests and class methods, now i want to add a command line interpreter (CLI).
As the bundler site tutorial for create gem,...
0
votes
1
answer
86
views
sharing singleton between tasks in ruby thor CLI
I'm implementing a ruby command line application (interactive application) and I'm using thor gem for CLI. I will have three tasks, and one of the tasks is loading the external files and storing it. ...
2
votes
4
answers
865
views
How to add --help, -h flag to Thor command?
I created a Thor class inside a Ruby executable, and it correctly shows the help when using ./foo help bar.
To make it more intuitive (for the sanity of my users), I'd also like to support ./foo bar -...
0
votes
1
answer
215
views
Ask required command-line input in Rails-Generator/Thor
I am building a generator in Ruby-on-Rails and was wondering if it's possible to ask for a required argument with Thor. Or if there's a decent workaround. Right now I'm just raising an exception:
@...
-1
votes
1
answer
96
views
How To Figure Out How Many Files and Directories Exist In A File Without Counting Files in Sub-Directories?
I'm currently working on the following problem for my class and I can't seem to figure out how to go about doing this. Everything I look up just leads me astray. Here is the question and thank you ...
0
votes
3
answers
551
views
Thor: run command without capturing stdout or stderr, and fail on error
I'm writing a Thor script to run some tests from a different tool i.e. running a shell command. I'd like the stdout and stderr from the command to continuously stream out into my console.
First ...
2
votes
1
answer
165
views
How to invoke a task twice in Thor
I need to invoke a task twice in Thor. In Rake, this could be accomplished by "re-enabling" it, but I can't find an equivalent in either of http://www.rubydoc.info/github/wycats/thor/master/Thor/...
3
votes
1
answer
731
views
On Ruby's Thor, How to show the command usage from within the application
I'm building a CLI using Ruby and Thor and I would like to print on the screen the command usage if no option is passed.
Something on the line of the pseudo code bellow:
Class Test < Thor
desc '...
1
vote
0
answers
113
views
ruby script runs differently with bundle exec
I have a ruby/thor script that uses savon to make a soap request. If I run the script on my desktop with:
thor my_script:my_action
everything works fine. If I run the script with:
bundle exec thor ...
1
vote
2
answers
1k
views
Thor CLI: Setting a custom order of commands in help output
The thor gem seems to always order the defined commands alphabetically when printing its help output. Example:
#!/usr/bin/env ruby
require "thor"
class MyCLI < Thor
desc "z", "this should go ...
2
votes
2
answers
1k
views
how to distribute a ruby script via homebrew
How can I deploy a simple ruby script via homebrew?
Here's what I tried
Wrote formula in a GitHub repo named homebrew-foo
# file https://github.com/foo/homebrew-foo/blob/master/foo.rb
class Foo <...
1
vote
1
answer
260
views
Is it possible to invoke Thor commands from my Web App?
Some time ago, I wrote a few command line applications using Ruby with the Thor gem. Now, I need to create a web interface for using exactly the same functionality existing in these CLI's. Is it ...
0
votes
1
answer
162
views
Unresolved external symbol with the THOR SFML extension
I want to use Thor library in a Visual Studio C++ project and I followed the instructions on the THOR website.
I think I linked the right directories to my project, the same thing I do to link SFML to ...
0
votes
1
answer
351
views
Why is there an extra blank line after using gsub on file in Ruby with Thor?
I have some Ruby code that processes a Gemfile. It adds some recommended gems and removes other gems. There's a section of a Gemfile that looks like the following:
group :development, :test do
# ...
4
votes
1
answer
767
views
Using RubyMine, how do I fix "Get available generators script executes with errors" warning?
In RubyMine 2017.1 (and maybe earlier), the "Messages" Tool Window, opens with the title "Messages Get available generators list" and displays
Warning:Get available generators script executes with ...
0
votes
1
answer
589
views
Ruby - run Thor command without argument
I have to use this command to execute the script:
$ruby file.rb keyword --format oneline --no-country-code --api-key=API
Where, the format, no-country-code, api-key are thor options. The keyword is ...
2
votes
1
answer
1k
views
Thor - command line option not recognized in method
I have to use this command to run my ruby program:
$ruby filename.rb NAME --from="People" --yell
And I have the script like this:
require 'thor'
class CLI < Thor
desc "hello NAME", "say hello ...
0
votes
1
answer
175
views
Ruby Thor options with white space
for an assignment I am doing I am required to have an option "--format oneline" where my output is formatted in one line.
I have successfully done this, but only if I use --formatoneline (without ...
-1
votes
1
answer
353
views
Ruby: calling method within another method's conditional statement
I'm trying to call the method print_json within a conditional statement that is contained in another method named list_trends. I did this becauese my code was starting to look too nested. However I ...
0
votes
1
answer
86
views
Ruby Thor Script through Symlink want calling directory
I want to get the current calling directory when calling a thor script - the script is processed through a Symlink.
So calling
say( "\n\t#{ Dir.pwd }\n\t" )
Returns the folder the script is hosted ...
0
votes
1
answer
155
views
ruby-thor calling multiple classes in a gem executable
I am learning ruby and thor.. and I am stuck here:
I have two classes in a module (both use Thor). I am able to use only one in the gem executable. When I add both like below and run it, I get Could ...
0
votes
1
answer
407
views
How to accept whitespace in string method options
I have an method that takes an string option containing whitespace:
desc 'events', 'List events'
method_option :since, :desc => 'Show events since', :default => "2 years ago"
def events
# .....
3
votes
1
answer
408
views
Use "global" Thorfile
I want to use Thor with thor-scmversion to bump the version of my Chef cookbooks. The normal way of using Thor is to create a Thorfile in the project folder and have tasks implemented in there. For my ...