Module: Brut::CLI

Defined in:
lib/brut/cli.rb,
lib/brut/cli/app_runner.rb,
lib/brut/cli/execution_results.rb

Overview

Brut provides a basic CLI framework for building CLIs that have access to your Brut app's innerworkings. This is an alternative to Rake tasks which suffer from poor usability and testability.

To create a CLI, you will subclass App. That class will define your UI as well as any subcommands that your CLI will respond to. See app.

Defined Under Namespace

Modules: Apps, ExecutionResults Classes: App, AppRunner, Command, Error, Executor, InvalidOption, Options, Output, SystemExecError

Class Method Summary collapse

Class Method Details

.app(app_klass, project_root:) ⇒ Object

Execute your CLI based on its command line invocation. You would call this method inside the executable file placed in bin/ in your project. For example, if you have YourApp::CLI::CleanOldFiles and you wish to execute it via bin/clean-files, you'd create bin/clean-files like so:

#!/usr/bin/env ruby

require "bundler"
Bundler.require
require "pathname"
require "brut/cli/apps/db"

exit Brut::CLI.app(YourApp::CLI::CleanOldFiles,
                   project_root: Pathname($0).dirname / "..")

it must be specified explicitly.

Parameters:

  • app_klass (Class)

    your CLI app's class.

  • project_root (Pathname)

    the path to the root of your project. This is needed before the Brut framework is initialized so



29
30
31
# File 'lib/brut/cli.rb', line 29

def self.app(app_klass, project_root:)
  Brut::CLI::AppRunner.new(app_klass:,project_root:).run!
end