Class: Laser::Cutter::CLI::Command
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- Laser::Cutter::CLI::Command
- Includes:
- Dry::CLI::UI
- Defined in:
- lib/laser/cutter/cli/command.rb
Overview
What every command inherits: the ui helpers, and the flags they all share.
Constant Summary collapse
- BAR_WIDTH =
Cells in a progress bar.
60
Class Method Summary collapse
- .finalize!(subclass) ⇒ Object
-
.inherited(subclass) ⇒ void
Gives every command the -v, --verbose flag.
Instance Method Summary collapse
-
#progress(label, total:) {|bar| ... } ⇒ Object
A green bar of BAR_WIDTH cells, or fewer when the terminal is narrower.
-
#ui ⇒ Dry::CLI::UI::Console
Boxes are as wide as help is.
Class Method Details
.finalize!(subclass) ⇒ Object
34 35 36 37 |
# File 'lib/laser/cutter/cli/command.rb', line 34 def self.finalize!(subclass) subclass.option :verbose, type: :boolean, default: false, aliases: ['-v'], desc: 'Print the configuration, and the full backtrace on failure' end |
.inherited(subclass) ⇒ void
This method returns an undefined value.
Gives every command the -v, --verbose flag.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/laser/cutter/cli/command.rb', line 17 def self.inherited(subclass) super # Add --verbose flag to the command, but at the very end of the class definition. trace = TracePoint.new(:end) do |tp| # skip nested classes closing inside the body next unless tp.self == subclass # disable the trace point trace.disable # add the verbose option to the subclass as the last option subclass.class_exec { finalize!(subclass) } end trace.enable(target_thread: Thread.current) end |
Instance Method Details
#progress(label, total:) {|bar| ... } ⇒ Object
A green bar of BAR_WIDTH cells, or fewer when the terminal is narrower.
52 53 54 55 56 |
# File 'lib/laser/cutter/cli/command.rb', line 52 def progress(label, total:, &) Dry::CLI::UI::Console .new(out: out, err: err, box_width: CLI.help_width, width: progress_width(label)) .progress(label, total: total, color: :green, &) end |