Questions tagged [thor]

Thor is a scripting framework that replaces Rake, Sake and RubiGen.

Thor is a toolkit for building powerful command-line interfaces.
It is a scripting framework that replaces Rake, Sake and RubiGen.
Thor is open source and on github.

232 questions
48
votes
4 answers

Rake vs. Thor for automation scripts?

I want to automate things like: Creating a new Ruby on Rails application with pre-selected database, Git initialize it, create a Heroku project, commit all files, etc. Upload all files in folder to another computer through SSH, but do not overwrite…
never_had_a_name
  • 90,630
  • 105
  • 267
  • 383
32
votes
3 answers

Run a CLI Thor app without arguments or task name

I'm looking for a way to create a command-line thor app that will run a default method without any arguments. I fiddled with Thor's default_method option, but still requires that I pass in an argument. I found a similar case where someone wanted to…
dhulihan
  • 11,053
  • 9
  • 40
  • 45
24
votes
6 answers

How to compose Thor tasks in separate classes/modules/files?

I'm having some trouble getting Thor to do this, so hopefully someone can point out what I'm doing wrong. I have a main class class MyApp < Thor that I want to break out into separate files for multiple namespaces, like thor create:app_type and…
Nick Klauer
  • 5,893
  • 5
  • 42
  • 68
20
votes
1 answer

Boson vs Thor for console applications

Has anyone used both Boson and Thor? Thor is very popular and has more followers and contributers than Boson, but Boson looks far more powerful than Thor and the architecture is very well thought out. In Boson you: can add methods that are used…
never_had_a_name
  • 90,630
  • 105
  • 267
  • 383
18
votes
2 answers

Where can I find good examples of testing a Thor script with RSpec?

Where can I find good examples of testing a Thor script with RSpec? My searches have so far not turned up anything good.
iconoclast
  • 21,213
  • 15
  • 102
  • 138
16
votes
2 answers

Namespacing thor commands in a standalone ruby executable

When calling thor commands on the command line, the methods are namespaced by their module/class structure, e.g. class App < Thor desc 'hello', 'prints hello' def hello puts 'hello' end end would be run with the command thor…
philnash
  • 70,667
  • 10
  • 60
  • 88
16
votes
3 answers

Adding a --version option to a Ruby Thor CLI

How do I add a --version option to my Ruby Thor command line interface application. For example I want to be able to run $ thor_app --version > thor_app version 1.0.0 This question is related to Run a CLI Thor app without arguments or task name,…
Morgan
  • 19,934
  • 8
  • 58
  • 84
13
votes
1 answer

How you do specify multiple arguments or parameters in Thor?

my_gem hello name1 name2 name3 give me a my_gem hello requires at least 1 argument: my_gem hello name Should I just parse them and separate the arguments with a delimeter? e.g my_gem hello name1,name2,name3,nameN In the file it would look…
poymode
  • 1,479
  • 3
  • 11
  • 14
12
votes
3 answers

Thor & YAML outputting as binary?

I'm using Thor and trying to output YAML to a file. In irb I get what I expect. Plain text in YAML format. But when part of a method in Thor, its output is different... class Foo < Thor include Thor::Actions desc "bar", "test" def set …
cp3
  • 2,119
  • 2
  • 22
  • 27
12
votes
3 answers

Thor Executable - Ignore Task Name

The thor wiki page, Making an Exectable, shows you how to create a thor powered CLI command that looks something like this: bash ./mythorcommand foo This requires you to pass in the thor task foo as the first argument. I can also run a thor…
dhulihan
  • 11,053
  • 9
  • 40
  • 45
12
votes
5 answers

How to make two thor tasks share options?

With Thor one can use method_option to set the options for a particular task. To set the options for all tasks in a class one can use class_option. But what about the case where one wants some tasks of a class, but not all, to share options? In the…
N.N.
  • 8,336
  • 12
  • 54
  • 94
11
votes
2 answers

Passing options to template function in thor

I am looking for a way to pass options to the ERB templating engine in thors template action. I stumbled upon the bundler cli source where thors template action is being used like this: opts = {:name => name, :constant_name => constant_name, …
devboy
  • 242
  • 2
  • 8
11
votes
2 answers

Interactive prompt with thor

I want to somehow ask the user to say their flickr_id, flickr_apikey and that stuff, but id' be most happy to do it under my install command so it dosn't end up being such a long and heavy line because of alle the arguments. so something like $ thor…
Oluf Nielsen
  • 769
  • 1
  • 8
  • 24
10
votes
5 answers

Call task more than once in Rails 3 generator

I'm writing a Rails 3 generator that creates two different models. Here's a very simplified example of what I'm trying to do: def my_generator_task invoke "model", ["foo"] invoke "model", ["bar"] end The problem is that the Thor invoke method…
balexand
  • 9,549
  • 7
  • 41
  • 36
10
votes
3 answers

Ruby/Thor exit status in case of an error

I'm new to Thor (and to Ruby) and I'm considering using it within a build script, as it's said it can be a replacement to Rake (thus to Make). However after a short trial, I'm confused about the error status it returns. I quickly went through the…
eruve
  • 661
  • 5
  • 12
1
2 3
15 16