module
AzuCLI::Utils
Overview
Centralized utilities module to eliminate code duplication Provides common functionality used across commands and generators
Extended Modules
Defined in:
azu_cli/utils.crConstant Summary
-
REQUIRED_CRYSTAL_VERSION =
"1.16.0" -
Required minimum Crystal version
Instance Method Summary
-
#azu_project? : Bool
Check if current directory is an Azu project
-
#binary_name : String
Get binary name from shard.yml targets Used by serve command to determine what to run
-
#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
-
#camel_case(str : String) : String
Convert string to camelCase "my_class" => "myClass"
-
#check_crystal_version : Bool
Check if current Crystal version meets requirements
-
#check_shard_version(shard_name : String, required_version : String) : Bool
Check if shard version is compatible
-
#command_exists?(command : String) : Bool
Check if command exists in PATH
-
#compare_versions(v1 : String, v2 : String) : Int32
Compare semantic versions Returns -1 if v1 < v2, 0 if equal, 1 if v1 > v2
-
#crystal_file?(path : String) : Bool
Check if a file is a Crystal source file
-
#crystal_version_info : NamedTuple(version: String, compatible: Bool)
Get Crystal version info
-
#dependency_version(shard_name : String) : String | Nil
Get dependency version from shard.yml
-
#detect_schema_info : Tuple(String, String)
Detect schema name from database configuration Returns tuple of {schema_name, schema_symbol}
-
#enforce_crystal_version!
Check Crystal version and exit if incompatible
-
#ensure_directory(path : String)
Ensure directory exists, create if not
-
#file_basename(path : String) : String
Get file basename without extension
-
#file_extension(path : String) : String
Get file extension
-
#generate_timestamp : String
Generate timestamp for migrations (YYYYMMDDHHmmSS format)
-
#generate_unique_timestamp : String
Generate timestamp with microseconds for unique IDs
-
#has_dependency?(shard_name : String) : Bool
Check if a shard dependency exists in shard.yml
-
#has_shard_yml? : Bool
Check if shard.yml exists
-
#indent(text : String, spaces : Int32 = 2) : String
Indent text by specified spaces
-
#kebab_case(str : String) : String
Convert string to kebab-case "MyClass" => "my-class"
-
#parse_migration_timestamp(filename : String) : String | Nil
Parse migration timestamp from filename "20240101120000_create_users.cr" => "20240101120000"
-
#pascal_case(str : String) : String
Convert string to PascalCase "my_class" => "MyClass"
-
#pluralize(word : String) : String
Pluralize a word (simple implementation) Handles common cases, may not be perfect for all words
-
#project_authors : Array(String)
Get project authors from shard.yml
-
#project_description : String | Nil
Get project description from shard.yml
-
#project_module_name : String
Get project module name from shard.yml Returns PascalCase module name (e.g., "MyProject")
-
#project_name : String
Get project name from shard.yml Returns project name or "app" as fallback
-
#project_version : String
Get project version from shard.yml
-
#reserved_keyword?(name : String) : Bool
Check if string is a reserved Crystal keyword
-
#run_command(command : String, args : Array(String) = [] of String) : NamedTuple(success: Bool, output: String, error: String)
Run shell command and capture output
-
#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
-
#safe_read_file(path : String) : String | Nil
Safely read file with error handling
-
#sanitize_database_url(url : String) : String
Sanitize database URL for safe logging
-
#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
-
#sanitize_hash_for_logging(hash : Hash) : Hash
Sanitize hash/options for logging (removes sensitive keys)
-
#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
-
#sanitize_log_message(message : String) : String
Sanitize log messages to remove sensitive information CRITICAL for security - prevents password/token leaks in logs
-
#sanitize_path(path : String, base_dir : String = ".") : String | Nil
Sanitize path - prevents directory traversal attacks CRITICAL for security when dealing with user-provided paths
-
#sanitize_path_component(component : String) : String | Nil
Validate and sanitize path component Use this for user-provided directory/file names in paths
-
#schema_file_path : String
Get schema file path
-
#schema_name : String
Get schema name from project
-
#screaming_snake_case(str : String) : String
Convert string to SCREAMING_SNAKE_CASE "myClass" => "MY_CLASS"
-
#singularize(word : String) : String
Singularize a word (simple implementation)
-
#snake_case(str : String) : String
Convert string to snake_case "MyClass" => "my_class"
-
#system_info : Hash(String, String)
Get system information for debugging
-
#template_file?(path : String) : Bool
Check if a file is a template file
-
#valid_class_name?(name : String) : Bool
Validate Crystal class/module name
-
#valid_identifier?(name : String) : Bool
Check if string is a valid Crystal identifier
-
#wrap_text(text : String, width : Int32 = 80) : String
Wrap text at specified width
Instance Method Detail
Get binary name from shard.yml targets Used by serve command to determine what to run
Build template context hash with common variables
Check if shard version is compatible
Compare semantic versions Returns -1 if v1 < v2, 0 if equal, 1 if v1 > v2
Detect schema name from database configuration Returns tuple of {schema_name, schema_symbol}
Parse migration timestamp from filename "20240101120000_create_users.cr" => "20240101120000"
Pluralize a word (simple implementation) Handles common cases, may not be perfect for all words
Get project module name from shard.yml Returns PascalCase module name (e.g., "MyProject")
Get project name from shard.yml Returns project name or "app" as fallback
Run shell command and capture output
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
Sanitize user input for use as file/directory name More restrictive than identifier - prevents path traversal This is CRITICAL for security
Sanitize hash/options for logging (removes sensitive keys)
Sanitize user input for use as Crystal identifier Removes/replaces invalid characters, ensures valid start This is critical for security - prevents code injection
Sanitize log messages to remove sensitive information CRITICAL for security - prevents password/token leaks in logs
Sanitize path - prevents directory traversal attacks CRITICAL for security when dealing with user-provided paths
Validate and sanitize path component Use this for user-provided directory/file names in paths
Convert string to SCREAMING_SNAKE_CASE "myClass" => "MY_CLASS"