问题标签 [thor]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
618 浏览

ruby - Thor YAML.load_file 无效的子类 (TypeError)

我正在创建一个 thor 脚本,该脚本基于存储 Ruby 结构的 yml 文件显示我所在的当前项目。尝试加载此 yml 文件时出现错误。

这是我要运行的脚本片段:

我已经三次检查了 irb 中的路径,它确实存在。我认为这是我的 YAML 存储我的 Ruby 结构的方式,但即使是控制台,我也会收到错误消息。这是我的 YAML 文件

有任何想法吗?我正在运行 Ruby 1.9.2p318。

0 投票
2 回答
2995 浏览

ruby - 捆绑安装从错误的目录运行

我正在thor为一些内部项目构建一个基于简单的生成器,并且似乎无法bundle install从正确的目录运行。

当我运行新的 [APP_NAME] 函数时,它应该创建目录和文件,然后运行bundle install以安装应用程序所需的 gem。

生成器函数的来源:

运行调用此创建方法的命令的控制台输出:

如您所见,它正在运行,bundle install但它在我的当前目录(thorbundlermy_gem)中运行,而不是在test_app目录(guardguard-coffeescriptguard-less和其他目录)中运行。

运行其他命令,例如lspwd给出预期结果:

不确定它是否有任何区别,但我使用 RVM 来管理我的红宝石。

0 投票
1 回答
4307 浏览

ruby - 如何在 Thor 中指定多个参数或参数?

my_gem 你好 name1 name2 name3 给我一个

my_gem hello 至少需要 1 个参数:my_gem hello name

我应该只解析它们并用分隔符分隔参数吗?

例如

my_gem 你好 name1,name2,name3,nameN

在文件中它看起来像

还是有办法做到这一点?

0 投票
1 回答
382 浏览

ruby-on-rails - 雷神不可用

我已经安装了 Ruby 1.9.2 以及安装 rails gem。我现在尝试使用以下命令创建一个新的 rails 应用程序:

我立即收到提示

我已经安装了雷神,但我不知道该怎么做。请帮忙。

警告,我是这方面的新手。

0 投票
0 回答
462 浏览

ruby - 使用 Thor,我怎样才能删除几个任务的选项?

我有一个使用 Thor 构建的 CLI。我的所有任务都需要一个全局选项,除了少数。我通过定义一个 class_option 添加了全局选项,但我无法弄清楚如何从选定的几个任务中删除该选项。如果我在其中一项任务中使用 remove_class_option() ,则全局选项将被永久删除,并且不再可用。

任何帮助,非常感谢!

0 投票
1 回答
264 浏览

ruby - 红宝石:雷神和 Httparty

我试图在我的类FindXYZ中使用 HTTParty 来扩展 Thor,但它不起作用。我想做的就是在我的方法xyz中使用 HTTParty get来查询 couchdb

当我尝试运行时,我看到错误找不到get

0 投票
2 回答
817 浏览

ruby-on-rails - 测试交互式雷神任务

我有以下雷神命令:

现在,显然,目前这只是在屏幕上输出一些语言。但是,我需要做的是为测试输出的命令编写一个测试,正如我所期望的那样,当我开始从事繁重的工作时,我可以将这些东西存根。

我看过Aruba,但出于某种原因,这似乎不喜欢交互性,目前尚不清楚原因。

因此,是否有人对如何测试(使用 RSpec)有任何想法?

0 投票
1 回答
804 浏览

ruby - Thor:当我定义了一个参数时,如何让我的 Thor 任务显示帮助?

我正在将一个小项目转换为使用 Thor,并且心不在焉的我想使用内置帮助记录可用的任务。但是,如果我使用参数定义任务,任务级帮助将恢复为类的帮助 - 这意味着不会显示任务描述或预期参数的详细信息。

我希望能够拥有一个可以使用参数而不是参数调用的方法,因此可以像这样使用它

我已将问题归结为以下 thorfile,除了损坏的帮助输出之外,它可以按我的意愿工作。我已经去掉了任何其他参数,因为它们对问题没有影响。第一个任务 ok:foo 将正常显示帮助,第二个任务 broken:foo 帮助不大:

请求 ok:foo 任务方法的帮助给出:

为 break:foo 任务请求帮助的帮助不大:

如何定义参数并显示正确的任务帮助?

0 投票
3 回答
1716 浏览

ruby - How do I remove leading whitespace from a Ruby Heredoc, while maintaing 2 leading spaces

This question is partly answered in How do I remove leading whitespace chars from Ruby HEREDOC?

In Rails 3 there is a method #strip_heredoc, that strips all whitespace. But when inserting lines in an existing file, that already has identation, this doesn't work too well. An example:

The 'begin' and 'end' are only added to show that the source code has indentation. The heredoc has 4 spaces before the line '# for devise'. @strip_heredoc will delete all these spaces, but it will maintain the two extra spaces in the line 'do stuff'.

In environments/production.rb this will look like this:

How to solve this? Maybe there are other ways instead of a heredoc? I thought maybe strip_heredoc(min) where min is the minimum of spaces to keep, but that doesn't work well with tabs I guess. Or have the first line of the heredoc determine the left margin, like this:

That 'FIRST_LINE' would be deleted by strip_heredoc, but it would also set the number of spaces/whitespace that needs to be deleted. So the output would have 2 spaces in front of 'Real code here'.

Update: Maybe something like this:

0 投票
1 回答
837 浏览

ruby - 使用 get 或 ARGF.readline 时,Thor 任务抛出错误

这是雷神任务:

当我运行命令时,我收到此错误:

./mycommand:26:in `gets': 没有这样的文件或目录 - readkeys (Errno::ENOENT)

有任何想法吗?语法似乎很好。