module

AzuCLI::Utils

Centralized utilities module to eliminate code duplication Provides common functionality used across commands and generators

Constants

REQUIRED_CRYSTAL_VERSION = "1.16.0"

Required minimum Crystal version

Instance methods

azu_project?

Check if current directory is an Azu project

Source
binary_name

Get binary name from shard.yml targets Used by serve command to determine what to run

Source
build_template_context(name : String, attributes : Hash(String, String) = {} of String => String, options : Hash(String, String) = {} of String => String) : Hash(String, String | Array(String) | Hash(String, String))

Build template context hash with common variables

Source
camel_case(str : String) : String

Convert string to camelCase "my_class" => "myClass"

Source
check_crystal_version

Check if current Crystal version meets requirements

Source
check_shard_version(shard_name : String, required_version : String) : Bool

Check if shard version is compatible

Source
command_exists?(command : String) : Bool

Check if command exists in PATH

Source
compare_versions(v1 : String, v2 : String) : Int32

Compare semantic versions Returns -1 if v1 < v2, 0 if equal, 1 if v1 > v2

Source
crystal_file?(path : String) : Bool

Check if a file is a Crystal source file

Source
crystal_version_info

Get Crystal version info

Source
dependency_version(shard_name : String) : String | Nil

Get dependency version from shard.yml

Source
detect_schema_info

Detect schema name from database configuration Returns tuple of {schema_name, schema_symbol} Matches CQL schema patterns like: BlogDB = CQL::Schema.define(...) or CQL::Schema.build(...)

Source
enforce_crystal_version!

Check Crystal version and exit if incompatible

Source
ensure_directory(path : String)

Ensure directory exists, create if not

Source
file_basename(path : String) : String

Get file basename without extension

Source
file_extension(path : String) : String

Get file extension

Source
generate_timestamp

Generate timestamp for migrations (YYYYMMDDHHmmSS format)

Source
generate_unique_timestamp

Generate timestamp with microseconds for unique IDs

Source
has_dependency?(shard_name : String) : Bool

Check if a shard dependency exists in shard.yml

Source
has_shard_yml?

Check if shard.yml exists

Source
indent(text : String, spaces : Int32 = 2) : String

Indent text by specified spaces

Source
kebab_case(str : String) : String

Convert string to kebab-case "MyClass" => "my-class"

Source
parse_migration_timestamp(filename : String) : String | Nil

Parse migration timestamp from filename "20240101120000_create_users.cr" => "20240101120000"

Source
pascal_case(str : String) : String

Convert string to PascalCase "my_class" => "MyClass"

Source
pluralize(word : String) : String

Pluralize a word (simple implementation) Handles common cases, may not be perfect for all words

Source
project_authors

Get project authors from shard.yml

Source
project_description

Get project description from shard.yml

Source
project_module_name

Get project module name from shard.yml Returns PascalCase module name (e.g., "MyProject")

Source
project_name

Get project name from shard.yml Returns project name or "app" as fallback

Source
project_version

Get project version from shard.yml

Source
reserved_keyword?(name : String) : Bool

Check if string is a reserved Crystal keyword

Source
run_command(command : String, args : Array(String) = [] of String) : NamedTuple(success: Bool, output: String, error: String)

Run shell command and capture output

Source
safe_identifier(name : String) : String | Nil

Validate and sanitize user input for use as identifier Returns sanitized name or nil if invalid Use this when you need a guaranteed valid identifier

Source
safe_read_file(path : String) : String | Nil

Safely read file with error handling

Source
sanitize_database_url(url : String) : String

Sanitize database URL for safe logging

Source
sanitize_filename(name : String) : String

Sanitize user input for use as file/directory name More restrictive than identifier - prevents path traversal This is CRITICAL for security

Source
sanitize_hash_for_logging(hash : Hash) : Hash

Sanitize hash/options for logging (removes sensitive keys)

Source
sanitize_identifier(name : String) : String

Sanitize user input for use as Crystal identifier Removes/replaces invalid characters, ensures valid start This is critical for security - prevents code injection

Source
sanitize_log_message(message : String) : String

Sanitize log messages to remove sensitive information CRITICAL for security - prevents password/token leaks in logs

Source
sanitize_path(path : String, base_dir : String = ".") : String | Nil

Sanitize path - prevents directory traversal attacks CRITICAL for security when dealing with user-provided paths

Source
sanitize_path_component(component : String) : String | Nil

Validate and sanitize path component Use this for user-provided directory/file names in paths

Source
schema_file_path

Get schema file path

Source
schema_name

Get schema name from project

Source
screaming_snake_case(str : String) : String

Convert string to SCREAMING_SNAKE_CASE "myClass" => "MY_CLASS"

Source
singularize(word : String) : String

Singularize a word (simple implementation)

Source
snake_case(str : String) : String

Convert string to snake_case "MyClass" => "my_class"

Source
system_info

Get system information for debugging

Source
template_file?(path : String) : Bool

Check if a file is a template file

Source
valid_class_name?(name : String) : Bool

Validate Crystal class/module name

Source
valid_identifier?(name : String) : Bool

Check if string is a valid Crystal identifier

Source
wrap_text(text : String, width : Int32 = 80) : String

Wrap text at specified width

Source