24
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Thorでサブコマンドを定義する

Last updated at Posted at 2012-10-02

Thorでは以下のようなサブコマンド、サブサブコマンドも簡単に作ることができます。

$ ./foo bar baz qux
qux
foo
require 'thor'
require 'thor/group'

class Baz < Thor
  namespace 'bar baz'

  desc 'qux', 'qux!!!'
  def qux
    puts 'qux'
  end

  def self.banner(task, namespace = false, subcommand = true)
    super
  end
end

class Bar < Thor
  namespace :bar
  register(Baz, 'baz', 'baz [COMMAND]', 'subcommad for baz')

  def self.banner(task, namespace = false, subcommand = true)
    super
  end
end

class Foo < Thor
  register(Bar, 'bar', 'bar [COMMAND]', 'commands for bar')
end
Foo.start
24
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?