Module: Strata::CLI::Output
- Included in:
- Generators::Group, Helpers::CommandContext, Main, SubCommands::Audit, SubCommands::Branch, SubCommands::Datasource, SubCommands::Deploy, SubCommands::Project, SubCommands::Table
- Defined in:
- lib/strata/cli/output.rb
Constant Summary collapse
- THEME =
{ success: :green, error: %i[red bold], warning: :yellow, info: :cyan, title: %i[cyan bold], highlight: %i[cyan bold], dim: :bright_black, primary: :blue, secondary: :magenta, border: %i[cyan dim], selected: %i[green bold], disabled: :bright_black }.freeze
Class Method Summary collapse
- .format(type, message) ⇒ Object
- .pastel ⇒ Object
- .print_error(message, context: nil) ⇒ Object
- .print_hint(message, context: nil, stderr: false) ⇒ Object
- .print_info(message, context: nil) ⇒ Object
-
.print_status(label, message, type: :info, context: nil) ⇒ Object
Standard status output with Thor’s prefix formatting.
- .print_success(message, context: nil) ⇒ Object
- .print_warning(message, context: nil) ⇒ Object
- .shell_for(context = nil) ⇒ Object
-
.thor_color(type) ⇒ Object
Thor only understands a limited palette; keep it simple/stable.
Instance Method Summary collapse
- #print_error(message) ⇒ Object
- #print_hint(message, stderr: false) ⇒ Object
-
#print_info(message) ⇒ Object
Convenience instance methods for Thor classes.
- #print_status(label, message, type: :info) ⇒ Object
- #print_success(message) ⇒ Object
- #print_warning(message) ⇒ Object
Class Method Details
.format(type, message) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/strata/cli/output.rb', line 65 def format(type, ) return "" if .nil? styles = THEME[type] return .to_s unless styles if styles.is_a?(Array) pastel.decorate(.to_s, *styles) else pastel.send(styles, .to_s) end end |
.pastel ⇒ Object
25 26 27 |
# File 'lib/strata/cli/output.rb', line 25 def pastel @pastel ||= Pastel.new(enabled: $stdout.tty?) end |
.print_error(message, context: nil) ⇒ Object
48 49 50 |
# File 'lib/strata/cli/output.rb', line 48 def print_error(, context: nil) shell_for(context).say_error(format(:error, )) end |
.print_hint(message, context: nil, stderr: false) ⇒ Object
52 53 54 55 56 |
# File 'lib/strata/cli/output.rb', line 52 def print_hint(, context: nil, stderr: false) shell = shell_for(context) formatted = format(:dim, ) stderr ? shell.say_error(formatted) : shell.say(formatted) end |
.print_info(message, context: nil) ⇒ Object
36 37 38 |
# File 'lib/strata/cli/output.rb', line 36 def print_info(, context: nil) shell_for(context).say(format(:info, )) end |
.print_status(label, message, type: :info, context: nil) ⇒ Object
Standard status output with Thor’s prefix formatting. We keep the label color via Thor, but decorate the message via Output theme.
60 61 62 63 |
# File 'lib/strata/cli/output.rb', line 60 def print_status(label, , type: :info, context: nil) shell = shell_for(context) shell.say_status(label, format(type, ), thor_color(type)) end |
.print_success(message, context: nil) ⇒ Object
40 41 42 |
# File 'lib/strata/cli/output.rb', line 40 def print_success(, context: nil) shell_for(context).say(format(:success, )) end |
.print_warning(message, context: nil) ⇒ Object
44 45 46 |
# File 'lib/strata/cli/output.rb', line 44 def print_warning(, context: nil) shell_for(context).say(format(:warning, )) end |
.shell_for(context = nil) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/strata/cli/output.rb', line 29 def shell_for(context = nil) return context.shell if context&.respond_to?(:shell) return context if context.is_a?(Thor::Shell) Thor::Shell::Color.new end |
.thor_color(type) ⇒ Object
Thor only understands a limited palette; keep it simple/stable.
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/strata/cli/output.rb', line 79 def thor_color(type) case type when :success then :green when :error then :red when :warning then :yellow when :info, :title, :border then :cyan when :primary then :blue when :secondary then :magenta when :dim then :white else :white end end |
Instance Method Details
#print_error(message) ⇒ Object
98 |
# File 'lib/strata/cli/output.rb', line 98 def print_error() = Output.print_error(, context: self) |
#print_hint(message, stderr: false) ⇒ Object
99 |
# File 'lib/strata/cli/output.rb', line 99 def print_hint(, stderr: false) = Output.print_hint(, context: self, stderr: stderr) |
#print_info(message) ⇒ Object
Convenience instance methods for Thor classes.
95 |
# File 'lib/strata/cli/output.rb', line 95 def print_info() = Output.print_info(, context: self) |
#print_status(label, message, type: :info) ⇒ Object
100 |
# File 'lib/strata/cli/output.rb', line 100 def print_status(label, , type: :info) = Output.print_status(label, , type: type, context: self) |
#print_success(message) ⇒ Object
96 |
# File 'lib/strata/cli/output.rb', line 96 def print_success() = Output.print_success(, context: self) |
#print_warning(message) ⇒ Object
97 |
# File 'lib/strata/cli/output.rb', line 97 def print_warning() = Output.print_warning(, context: self) |