thor

Is it possible to call Git or other command line tools from inside a Thor script?

三世轮回 提交于 2019-12-06 03:20:54
问题 I find that I'm often running a sequence of routine 'cleanup' tasks before and after I make a git commit for my Rails 3 app. I was thinking about putting these things into a Thor script, but one thing I haven't been able to figure out is how to use Thor (or Rake) to call other tools on the system. Is it possible to call a command like git log from a Thor or Rake script, and if so what does that look like? Thanks! 回答1: Just shell out: result = %x(git log) puts result or system('git log') if

How do I create thor::group generators as args of my_command

怎甘沉沦 提交于 2019-12-05 04:39:18
问题 In my gem I'd like to have a an executable command with args like so: foo generate project foo generate config foo say_hi So I made foo/bin/foo #!/usr/bin/env ruby require 'foo' Foo::Foo.start And the Foo file in foo/lib/thor/foo.rb module Foo class Foo < Thor desc "generate [WHAT]" def generate(*args) end desc "say_hi" def say_hi(*args) .... end end end And foo/lib/thor/generators/project.rb And foo/lib/thor/generators/config.rb Where I'd like to specify classes inherited from Thor::Group

Thor Executable - Ignore Task Name

心不动则不痛 提交于 2019-12-04 18:42:21
问题 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 executable without any arguments using thor's default_method : bash ./mythorcommand However, I'd like to pass in a variable string as the first argument: bash ./mythorcommand "somevalue" This doesn't work because thor commands expect the first argument to

How to make two thor tasks share options?

ぐ巨炮叔叔 提交于 2019-12-04 18:07:49
问题 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 following task1 and task2 shares options but they do not share all options and they share no options with task3 . require 'thor' class Cli < Thor desc 'task1', 'Task 1' method_option :type, :type => :string, :required => true, :default => 'foo'

How do I create thor::group generators as args of my_command

北战南征 提交于 2019-12-03 21:49:36
In my gem I'd like to have a an executable command with args like so: foo generate project foo generate config foo say_hi So I made foo/bin/foo #!/usr/bin/env ruby require 'foo' Foo::Foo.start And the Foo file in foo/lib/thor/foo.rb module Foo class Foo < Thor desc "generate [WHAT]" def generate(*args) end desc "say_hi" def say_hi(*args) .... end end end And foo/lib/thor/generators/project.rb And foo/lib/thor/generators/config.rb Where I'd like to specify classes inherited from Thor::Group like katz examples ... module Foo module Generators class Project < Thor::Group include Thor::Actions ...

Rake vs. Thor for automation scripts?

不羁岁月 提交于 2019-12-03 18:20:14
问题 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 files. Upgrade Ubuntu, install all basic packages through apt-get. From what I understand, tools for this are Rake and Thor, however, which one should I use? Rake seems to me more de-facto and popular. I have heard people recommending Thor. How do

Thor Executable - Ignore Task Name

瘦欲@ 提交于 2019-12-03 12:15:50
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 executable without any arguments using thor's default_method : bash ./mythorcommand However, I'd like to pass in a variable string as the first argument: bash ./mythorcommand "somevalue" This doesn't work because thor commands expect the first argument to the be a task name. Is there a way to ignore the task name and send the first argument to a default

How to make two thor tasks share options?

烂漫一生 提交于 2019-12-03 11:26:50
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 following task1 and task2 shares options but they do not share all options and they share no options with task3 . require 'thor' class Cli < Thor desc 'task1', 'Task 1' method_option :type, :type => :string, :required => true, :default => 'foo' def task1 end desc 'task2', 'Task 2' method_option :type, :type => :string, :required => true, :default =

Namespacing thor commands in a standalone ruby executable

风流意气都作罢 提交于 2019-12-03 03:52:51
问题 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 app:hello However, if you make that self executable by putting App.start at the bottom you can run the command like: app hello Is there any way to namespace those commands? So that you could call, for example app say:hello app say:goodbye 回答1: Another way of doing this is

Run a CLI Thor app without arguments or task name

感情迁移 提交于 2019-12-03 01:14:54
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 run a CLI Thor task with arguments but without a task name. I'd like to run a task with no task name and no arguments. Is such a thing possible? It seems the proper Thor-way to do this is using default_task : class Commands < Thor desc "whatever", "The default task to run when no command is given" def whatever ... end default_task :whatever end