core.rootpath #
Rootpath Module
The rootpath module provides functionality for managing the Hero environment directory structure and path handling. It ensures consistent access to Hero-specific directories and provides utilities for path manipulation.
Core Functions
Directory Management
herodir()- Returns the root directory for the Hero environment (~/hero)bindir()- Returns the binary directory (~/hero/bin)vardir()- Returns the variable directory (~/hero/var)cfgdir()- Returns the configuration directory (~/hero/cfg)ensure_hero_dirs()- Creates all necessary Hero directories if they don't exist
Path Utilities
shell_expansion(s string)- Expands shell-like path expressions (e.g.,~or{HOME}) to full pathspath_ensure(s string)- Ensures a given path exists by creating it if necessaryhero_path(s string)- Constructs a path underneath the Hero root directoryhero_path_ensure(s string)- Ensures a Hero-specific path exists and returns it
Usage Example
import incubaid.herolib.core.rootpath
// Get and ensure Hero directories exist
hero_root := rootpath.ensure_hero_dirs()
// Work with Hero-specific paths
ensured_path := rootpath.hero_path_ensure('data/myapp')
// Expand shell paths
full_path := rootpath.shell_expansion('~/hero/custom/path')
Directory Structure
The module manages the following directory structure:
~/hero/
├── bin/ # Binary files
├── var/ # Variable data
└── cfg/ # Configuration files
fn bindir #
fn bindir() string
bin dir
fn cfgdir #
fn cfgdir() string
cfg dir
fn ensure_hero_dirs #
fn ensure_hero_dirs() string
ensure_hero_dirs creates all necessary hero directories
fn hero_path #
fn hero_path(s string) string
get path underneath the hero root directory
fn hero_path_ensure #
fn hero_path_ensure(s string) string
return path and ensure it exists and return the path
fn herodir #
fn herodir() string
root dir for our hero environment
fn path_ensure #
fn path_ensure(s string) string
path_ensure ensures the given path exists and returns it
fn shell_expansion #
fn shell_expansion(s_ string) string
replace ~ to home dir in string as given
fn vardir #
fn vardir() string
var dir