Module: Omnizip::Shared
- Included in:
- ArchiveCommands, Cli, ProfileCommands
- Defined in:
- lib/omnizip/cli.rb
Overview
Shared helpers used by the Thor command groups defined below (ProfileCommands, ArchiveCommands, Cli). Defined here because the command classes include it at class-body time; a separate file under Omnizip::Cli would re-trigger this file's autoload mid-load.
Instance Method Summary collapse
-
#format_bytes(bytes) ⇒ String
Format a byte count with a binary-unit suffix.
-
#handle_error(error) ⇒ Object
Print a formatted error message and exit nonzero.
Instance Method Details
#format_bytes(bytes) ⇒ String
Format a byte count with a binary-unit suffix.
40 41 42 43 44 45 46 47 48 |
# File 'lib/omnizip/cli.rb', line 40 def format_bytes(bytes) return "0 B" if bytes.zero? units = %w[B KB MB GB TB] exp = (Math.log(bytes) / Math.log(1024)).to_i exp = [exp, units.size - 1].min "%.1f %s" % [bytes.to_f / (1024**exp), units[exp]] end |
#handle_error(error) ⇒ Object
Print a formatted error message and exit nonzero.
31 32 33 34 |
# File 'lib/omnizip/cli.rb', line 31 def handle_error(error) warn Omnizip::CliOutputFormatter.format_error(error) exit 1 end |