Skip to content
mosop edited this page Jul 25, 2021 · 7 revisions

Defining Commands

To define a command, define a class and inherit Cli::Command.

class Smile < Cli::Command
end

Running Commands

To run a command, define a #run method in your command class and call the .run method.

class Smile < Cli::Command
  def run
    puts ":)"
  end
end

Smile.run

This prints:

:)

Passing Arguments

To pass arguments to a command, call .run with arguments.

class Smile < Cli::Command
  def run
    puts "#{args[0]} :)"
  end
end

Smile.run %w(hello)

This prints:

hello :)

Clone this wiki locally