thor

How to test stdin for a CLI using rspec

旧巷老猫 提交于 2019-12-22 08:38:27
问题 I'm making a small Ruby program and can't figure out how to write RSpec specs that simulate multiple user command line inputs (the functionality itself works). I think this StackOverflow answer probably covers ground that is closest to where I am, but it's not quite what I need. I am using Thor for the command line interface, but I don't think this is an issue with anything in Thor. The program can read in commands either from a file or the command line, and I've been able to successfully

Run a CLI Thor app without arguments or task name

北战南征 提交于 2019-12-20 10:34:50
问题 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? 回答1: It seems the proper Thor-way to do this is using default_task : class Commands < Thor desc

Call task more than once in Rails 3 generator

别说谁变了你拦得住时间么 提交于 2019-12-18 12:27:57
问题 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 only invokes a task once, so the second call to the "model" task never happens and the "bar" model is never created. Does anyone know an elegant way to accomplish this, preferably in a way that doesn't break the ability to run "rails destroy" with the

How to change source for a custom rails generator? (Thor)

偶尔善良 提交于 2019-12-13 15:53:30
问题 I'm making a custom generator that generates a new rails app, and I do it like this require 'thor' require 'rails/generators/rails/app/app_generator' class AppBuilder < Rails::AppBuilder include Thor::Actions include Thor::Shell ... end The problem is, how do I add a new source directory (which is then used by Thor::Actions#copy_file , Thor::Actions#template , and the others)? I saw in the Thor's documentation that Thor::Actions#source_paths holds the sources (it's an array of paths), so I

How do you make ruby variables and methods in scope using Thor Templates?

老子叫甜甜 提交于 2019-12-13 00:53:36
问题 I'm trying to use the Thor::Actions template method to generate some C++ test file templates, but erb keeps telling me that I have undefined variables and methods. Here's the calling code: def test (name, dir) template "tasks/templates/new_test_file", "src/#{dir}/test/#{name}Test.cpp" insert_into_file "src/#{dir}/test/CMakeLists.txt", "#{dir}/test/#{name}Test ", :after => "set(Local " end Here's the template: <% test_name = name + "Test" %> #include <gtest/gtest.h> #include "<%= dir %>/<%=

How to invoke a task twice in Thor

不想你离开。 提交于 2019-12-12 22:13:39
问题 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/Invocation or https://github.com/erikhuda/thor/wiki/Invocations Some background, because of old code, sometimes I need to reset a database between tests (I know this is not ideal, but this is old code), so my scenario is like desc "all-tests", "all the tests" def all_tests invoke :"clean-db" invoke :

雷神 Thor —— TiDB 自动化运维平台

柔情痞子 提交于 2019-12-10 13:51:06
作者:瞿锴,同程艺龙资深 DBA 背景介绍 随着互联网的飞速发展,业务量可能在短短的时间内爆发式地增长,对应的数据量可能快速地从几百 GB 涨到几百个 TB,传统的单机数据库提供的服务,在系统的可扩展性、性价比方面已经不再适用。为了应对大数据量下业务服务访问的性能问题,MySQL 数据库常用的分库、分表方案会随着 MySQL Sharding(分片)的增多,业务访问数据库逻辑会越来越复杂。而且对于某些有多维度查询需求的表,需要引入额外的存储或牺牲性能来满足查询需求,这样会使业务逻辑越来越重,不利于产品的快速迭代。 TiDB 的架构 TiDB 作为 PingCAP 旗下开源的分布式数据库产品,具有多副本强一致性的同时能够根据业务需求非常方便的进行弹性伸缩,并且扩缩容期间对上层业务无感知。TiDB 包括三大核心组件:TiDB/TiKV/PD。 TiDB Server:主要负责 SQL 的解析器和优化器,它相当于计算执行层,同时也负责客户端接入和交互。 TiKV Server:是一套分布式的 Key-Value 存储引擎,它承担整个数据库的存储层,数据的水平扩展和多副本高可用特性都是在这一层实现。 PD Server:相当于分布式数据库的大脑,一方面负责收集和维护数据在各个 TiKV 节点的分布情况,另一方面 PD 承担调度器的角色

Thor Argument Error when trying to create a new Rails app

走远了吗. 提交于 2019-12-10 13:26:32
问题 I'm trying to create a new app using rails-api . When I run rails-api new mynewapp I get the following: /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1.1/lib/thor/parser/option.rb:125:in `validate_default_type!': An option's default must match its type. (ArgumentError) from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1.1/lib/thor/parser/option.rb:111:in `validate!' from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1.1

'rails new' creates a `validate_default_type!': An option's default must match its type. (ArgumentError) error

允我心安 提交于 2019-12-10 13:25:12
问题 I am trying to create a new Ruby on Rails application. Every time I type in rails new after, I get this error /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:130:in `validate_default_type!': An option's default must match its type. (ArgumentError) from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:113:in `validate!' from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/argument.rb:24:in `initialize' from /usr/local/lib/ruby

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

拟墨画扇 提交于 2019-12-08 14:40:03
问题 Where can I find good examples of testing a Thor script with RSpec? My searches have so far not turned up anything good. 回答1: Try out Thor's own repo at https://github.com/wycats/thor/tree/master/spec 回答2: I'm trying to do rspec tests for thor in my homedir project (in the homedir3 branch, at the moment). Look in the CLI_spec.rb file. I don't claim they are the paragon of unit tests but it's something to look at. 来源: https://stackoverflow.com/questions/7061988/where-can-i-find-good-examples