module Comandante::Helper

Overview

Some helper functions

Defined in:

comandante/helper.cr

Constant Summary

EMPTY_STRING_ARRAY = Array(String).new

Class Method Summary

Class Method Detail

def self.assert(cond, msg) : Nil #

Asserts a condition, depending on Cleaner will either exit with message or raise an error

Example:

assert(value > 0, "Expecting a value > 0")

[View source]
def self.assert_directory(dir) : Nil #

Asserts that a directory exists


[View source]
def self.assert_file(file) : Nil #

Asserts that a file exists


[View source]
def self.debug_inspect(val, context = "") #

Prints a colorized inspect of val if Cleaner is in debug mode

Example:

debug_inspect(@opts, context: "@opts")
debug_inspect({test: x == y})
debug_inspect(["one", "two"])

[View source]
def self.file_md5sum(path) : String #

Returns md5 digest for file


[View source]
def self.file_sha1sum(path) : String #

Returns sha1 digest for file


[View source]
def self.file_sha256sum(path) : String #

Returns sha256 digest for file


[View source]
def self.file_sha512sum(path) : String #

Returns sha512 digest for file


[View source]
def self.mkdir(dir : String, verbose = false) #

mkdir with verbose option


[View source]
def self.parse_yaml(str, context = "") : YAML::Any #

Parses yaml string and fails with message, context is used in error messages


[View source]
def self.put_debug(msg, pref = "Debug: ") #

Prints a debug message if Cleaner is in debug mode


[View source]
def self.put_error(msg, pref = "Error: ") #

Prints an error message to STDERR


[View source]
def self.put_verbose(msg) #

Prints a message to STDERR if in verbose mode


[View source]
def self.put_warning(msg, pref = "Warning: ") #

Prints a warning message to STDERR


[View source]
def self.read_gzip(path, &) : Nil #

Reads gziped file line by line

read_gzip(path) { |line| puts line }

[View source]
def self.read_gzip(path) : String #

Reads gziped file into a string


[View source]
def self.read_yaml(file : String) : YAML::Any #

Parses yaml from file and fails with message


[View source]
def self.run(cmd, args = EMPTY_STRING_ARRAY, msg = "cmd failed") : Nil #

Runs a command using system and raises if command fails


[View source]
def self.string_md5sum(path) : String #

Returns md5 digest for string


[View source]
def self.string_sha1sum(path) : String #

Returns sha1 digest for string


[View source]
def self.string_sha256sum(path) : String #

Returns sha256 digest for string


[View source]
def self.string_sha512sum(path) : String #

Returns sha512 digest for string


[View source]
def self.string_to_file(str, file) : Nil #

Writes String to a file


[View source]
def self.timer(&) #

Timer for a block of commands, prints time at the end Examples

timer { do_something }

[View source]
def self.write_binary_file(file : String, data : Bytes) #

Writes Bytes to a file


[View source]
def self.write_gzip(str, path) : Nil #

Writes gziped file from a string


[View source]