Class Thor::Shell::Basic
In: lib/thor/shell/basic.rb
Parent: Object

Methods

Constants

DEFAULT_TERMINAL_WIDTH = 80

Attributes

base  [RW] 
padding  [R] 

Public Instance methods

Asks something to the user and receives a response.

If a default value is specified it will be presented to the user and allows them to select that value with an empty response. This option is ignored when limited answers are supplied.

If asked to limit the correct responses, you can pass in an array of acceptable answers. If one of those is not supplied, they will be shown a message stating that one of those answers must be given and re-asked the question.

If asking for sensitive information, the :echo option can be set to false to mask user input from $stdin.

If the required input is a path, then set the path option to true. This will enable tab completion for file paths relative to the current working directory on systems that support Readline.

Example

ask("What is your name?")

ask("What is the planet furthest from the sun?", :default => "Pluto")

ask("What is your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])

ask("What is your password?", :echo => false)

ask("Where should the file be saved?", :path => true)

Called if something goes wrong during the execution. This is used by Thor internally and should not be used inside your scripts. If something went wrong, you can always raise an exception. If you raise a Thor::Error, it will be rescued and wrapped in the method below.

Deals with file collision and returns true if the file should be overwritten and false otherwise. If a block is given, it uses the block response as the content for the diff.

Parameters

destination<String>:the destination file to solve conflicts
block<Proc>:an optional block that returns the value to be used in diff and merge

Sets the output padding while executing a block and resets it.

Mute everything that‘s inside given block

Check if base is muted

Make a question the to user and returns true if the user replies "n" or "no".

Sets the output padding, not allowing less than zero values.

Prints values in columns

Parameters

Array[String, String, …]

Prints a table.

Parameters

Array[Array[String, String, …]]

Options

indent<Integer>:Indent the first column by indent value.
colwidth<Integer>:Force the first column to colwidth spaces wide.

Prints a long string, word-wrapping the text to the current width of the terminal display. Ideal for printing heredocs.

Parameters

String

Options

indent<Integer>:Indent each line of the printed paragraph by indent value.

Say (print) something to the user. If the sentence ends with a whitespace or tab character, a new line is not appended (print + flush). Otherwise are passed straight to puts (behavior got from Highline).

Example

say("I know you knew that.")

Say a status with the given color and appends the message. Since this method is used frequently by actions, it allows nil or false to be given in log_status, avoiding the message from being shown. If a Symbol is given in log_status, it‘s used as the color.

This code was copied from Rake, available under MIT-LICENSE Copyright (c) 2003, 2004 Jim Weirich

Make a question the to user and returns true if the user replies "y" or "yes".

Protected Instance methods

Calculate the dynamic width of the terminal

[Validate]