You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.html
+8-1Lines changed: 8 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -418,8 +418,15 @@ <h2>Examples</h2>
418
418
'examples/complex.ini': "[sistema]\nnome=Sistema de Gerenciamento\ndescrição=Este é um sistema complexo com várias funcionalidades\nano-criação=2023\nversão=2.5.1\n\n[configurações]\nmodo debug=true\ndiretório de dados=C:\\Programa Files\\Sistema\\data\narquivos permitidos=.jpg, .png, .pdf, .docx\nURL=https://sistema.exemplo.com.br/api?token=abc123\ntempo-limite=60.5\n\n[usuários]\nadministrador=João Silva <joao@exemplo.com>\nformato_nome=Sobrenome, Nome\npermissões=leitura, escrita, execução ",
419
419
'examples/empty.ini': "# Arquivo de configuração vazio ",
420
420
'examples/basic_usage.sh': "#!/bin/bash\n# Basic usage example for the Bash INI Parser library\n\n# Load the library\nsource ../lib_ini.sh\n\necho \"Simple INI file operations example\"\necho\n\n# Set the configuration file\nCONFIG_FILE=\"simple_config.ini\"\necho \"Creating a test configuration file '$CONFIG_FILE'\"\n\n# Make sure we start with a clean file\nrm -f \"$CONFIG_FILE\"\n\n# Create sections and add values\necho \"1. Creating sections and adding values\"\nini_add_section \"$CONFIG_FILE\" \"general\"\nini_write \"$CONFIG_FILE\" \"general\" \"app_name\" \"My App\"\nini_write \"$CONFIG_FILE\" \"general\" \"version\" \"1.0.0\"\n\nini_add_section \"$CONFIG_FILE\" \"user\"\nini_write \"$CONFIG_FILE\" \"user\" \"name\" \"John Doe\"\nini_write \"$CONFIG_FILE\" \"user\" \"email\" \"john@example.com\"\n\n# Display the file contents\necho \"File contents after writing:\"\ncat \"$CONFIG_FILE\"\necho\n\n# Read values\necho \"2. Reading values\"\napp_name=$(ini_read \"$CONFIG_FILE\" \"general\" \"app_name\")\nversion=$(ini_read \"$CONFIG_FILE\" \"general\" \"version\")\nuser_name=$(ini_read \"$CONFIG_FILE\" \"user\" \"name\")\n\necho \"App name: $app_name\"\necho \"Version: $version\"\necho \"User name: $user_name\"\necho\n\n# List sections and keys\necho \"3. Listing sections and keys\"\necho \"Sections in the file:\"\nini_list_sections \"$CONFIG_FILE\" | while read section; do\n echo \"- $section\"\ndone\n\necho \"Keys in 'general' section:\"\nini_list_keys \"$CONFIG_FILE\" \"general\" | while read key; do\n echo \"- $key\"\ndone\necho\n\n# Update a value\necho \"4. Updating a value\"\necho \"Updating version to 1.1.0\"\nini_write \"$CONFIG_FILE\" \"general\" \"version\" \"1.1.0\"\nnew_version=$(ini_read \"$CONFIG_FILE\" \"general\" \"version\")\necho \"New version: $new_version\"\necho\n\n# Remove a key\necho \"5. Removing a key\"\necho \"Removing the 'email' key from 'user' section\"\nini_remove_key \"$CONFIG_FILE\" \"user\" \"email\"\necho \"File contents after removing key:\"\ncat \"$CONFIG_FILE\"\necho\n\n# Add a new section\necho \"6. Adding a new section\"\nini_add_section \"$CONFIG_FILE\" \"preferences\"\nini_write \"$CONFIG_FILE\" \"preferences\" \"theme\" \"dark\"\nini_write \"$CONFIG_FILE\" \"preferences\" \"language\" \"en-US\"\necho \"File contents after adding section:\"\ncat \"$CONFIG_FILE\"\necho\n\n# Remove a section\necho \"7. Removing a section\"\necho \"Removing the 'preferences' section\"\nini_remove_section \"$CONFIG_FILE\" \"preferences\"\necho \"File contents after removing section:\"\ncat \"$CONFIG_FILE\"\necho\n\n# Check if sections and keys exist\necho \"8. Checking existence\"\nif ini_section_exists \"$CONFIG_FILE\" \"general\"; then\n echo \"Section 'general' exists\"\nfi\n\nif ini_key_exists \"$CONFIG_FILE\" \"user\" \"name\"; then\n echo \"Key 'name' exists in section 'user'\"\nfi\n\nif ! ini_section_exists \"$CONFIG_FILE\" \"preferences\"; then\n echo \"Section 'preferences' does not exist anymore\"\nfi\necho\n\necho \"Basic operations completed successfully!\" ",
421
+
'examples/advanced_usage.sh': "#!/bin/bash\n# Advanced usage example for the improved lib_ini.sh library\n\n# Source the library\nsource ../lib_ini.sh\n\n# Enable debug mode to see what's happening\nINI_DEBUG=1\necho \"Debug mode enabled, you will see detailed information about operations\"\necho\n\n# Create a test configuration file\necho \"Creating a test configuration file 'config.ini'\"\nCONFIG_FILE=\"config.ini\"\n\n# Make sure we start with a clean file\nrm -f \"$CONFIG_FILE\"\n\n# Basic operations\necho \"=== Basic Operations ===\"\nini_add_section \"$CONFIG_FILE\" \"app\"\nini_write \"$CONFIG_FILE\" \"app\" \"name\" \"My Advanced App\"\nini_write \"$CONFIG_FILE\" \"app\" \"version\" \"2.0.0\"\nini_write \"$CONFIG_FILE\" \"app\" \"debug\" \"false\"\n\nini_add_section \"$CONFIG_FILE\" \"database\"\nini_write \"$CONFIG_FILE\" \"database\" \"host\" \"localhost\"\nini_write \"$CONFIG_FILE\" \"database\" \"port\" \"3306\"\nini_write \"$CONFIG_FILE\" \"database\" \"user\" \"dbuser\"\nini_write \"$CONFIG_FILE\" \"database\" \"password\" \"s3cr3t\"\n\necho \"Reading a basic value:\"\napp_name=$(ini_read \"$CONFIG_FILE\" \"app\" \"name\")\necho \"App name: $app_name\"\necho\n\n# Working with default values\necho \"=== Default Values ===\"\necho \"Reading a value with default (exists):\"\ndebug=$(ini_get_or_default \"$CONFIG_FILE\" \"app\" \"debug\" \"true\")\necho \"Debug: $debug\"\n\necho \"Reading a value with default (doesn't exist):\"\ntimeout=$(ini_get_or_default \"$CONFIG_FILE\" \"app\" \"timeout\" \"30\")\necho \"Timeout: $timeout\"\necho\n\n# Working with arrays\necho \"=== Array Support ===\"\necho \"Writing array values:\"\nini_write_array \"$CONFIG_FILE\" \"app\" \"supported_formats\" \"jpg\" \"png\" \"gif\" \"svg\"\necho \"Reading array values:\"\nformats=$(ini_read_array \"$CONFIG_FILE\" \"app\" \"supported_formats\")\necho \"Supported formats:\"\nfor format in $formats; do\n echo \" - $format\"\ndone\necho\n\n# Complex values with spaces and special characters\necho \"=== Complex Values ===\"\nini_write \"$CONFIG_FILE\" \"app\" \"description\" \"This is a complex description with spaces and special characters: !@#$%^&*()\"\nini_write \"$CONFIG_FILE\" \"app\" \"welcome_message\" \"Welcome to \\\"My App\\\"\"\nini_write \"$CONFIG_FILE\" \"paths\" \"data_directory\" \"/path/with spaces/data\"\n\necho \"Reading complex values:\"\ndescription=$(ini_read \"$CONFIG_FILE\" \"app\" \"description\")\necho \"Description: $description\"\nmessage=$(ini_read \"$CONFIG_FILE\" \"app\" \"welcome_message\")\necho \"Welcome message: $message\"\necho\n\n# Export to environment variables\necho \"=== Environment Variables ===\"\nini_to_env \"$CONFIG_FILE\" \"CFG\"\necho \"Exported values to environment variables with prefix 'CFG'\"\necho \"Database host: $CFG_database_host\"\necho \"Database port: $CFG_database_port\"\necho \"App name: $CFG_app_name\"\necho\n\n# Import from another file\necho \"=== File Import ===\"\necho \"Creating another file 'defaults.ini'\"\nDEFAULTS_FILE=\"defaults.ini\"\nrm -f \"$DEFAULTS_FILE\"\n\nini_add_section \"$DEFAULTS_FILE\" \"logging\"\nini_write \"$DEFAULTS_FILE\" \"logging\" \"level\" \"info\"\nini_write \"$DEFAULTS_FILE\" \"logging\" \"file\" \"/var/log/app.log\"\nini_write \"$DEFAULTS_FILE\" \"logging\" \"max_size\" \"10M\"\n\nini_add_section \"$DEFAULTS_FILE\" \"security\"\nini_write \"$DEFAULTS_FILE\" \"security\" \"enable_2fa\" \"true\"\nini_write \"$DEFAULTS_FILE\" \"security\" \"password_expiry_days\" \"90\"\n\necho \"Importing from defaults.ini to config.ini\"\nini_import \"$DEFAULTS_FILE\" \"$CONFIG_FILE\"\n\necho \"Reading imported values:\"\nlog_level=$(ini_read \"$CONFIG_FILE\" \"logging\" \"level\")\necho \"Log level: $log_level\"\nenable_2fa=$(ini_read \"$CONFIG_FILE\" \"security\" \"enable_2fa\")\necho \"2FA enabled: $enable_2fa\"\necho\n\n# Check existence\necho \"=== Key Existence Check ===\"\nif ini_key_exists \"$CONFIG_FILE\" \"app\" \"version\"; then\n echo \"Key 'version' exists in section 'app'\"\nfi\n\nif ! ini_key_exists \"$CONFIG_FILE\" \"app\" \"non_existent_key\"; then\n echo \"Key 'non_existent_key' does not exist in section 'app'\"\nfi\necho\n\n# Remove operations\necho \"=== Remove Operations ===\"\necho \"Removing key 'debug' from section 'app'\"\nini_remove_key \"$CONFIG_FILE\" \"app\" \"debug\"\n\necho \"Removing section 'security'\"\nini_remove_section \"$CONFIG_FILE\" \"security\"\n\necho \"Final file contents:\"\ncat \"$CONFIG_FILE\"\necho\n\necho \"All operations completed successfully!\" ",
422
+
'examples/config.ini': "[app]\nname=My Advanced App\nversion=2.0.0\n\nsupported_formats=jpg,png,gif,svg\ndescription=This is a complex description with spaces and special characters: !@#$%^&*()\nwelcome_message=Welcome to \"My App\"\n[database]\nhost=localhost\nport=3306\nuser=dbuser\npassword=s3cr3t\n\n[paths]\ndata_directory=/path/with spaces/data\n\n[logging]\nlevel=info\nfile=/var/log/app.log\nmax_size=10M\n\n",
423
+
'examples/commented.ini': "# Configuração principal do serviço\n[service]\n# Nome do serviço\nname=FileManager\n# Porta que o serviço escuta\nport=8080\n; Comentário usando ponto e vírgula\ndebug=true\n\n; Seção de logging\n[logging]\n# Níveis: debug, info, warning, error\nlevel=info\n# Caminho para o arquivo de log\npath=/var/log/filemanager.log\n# Rotação de logs\nrotate=true\n# Tamanho máximo em MB\nmax_size=10\n\n# Configurações de autenticação\n[auth]\n# Tipo de autenticação: basic, token, oauth\ntype=oauth\n# Tempo de expiração do token em segundos\n; 3600 = 1 hora\nexpiration=3600 ",
'config.ini': "[app]\nname=My Advanced App\nversion=2.0.0\n\nsupported_formats=jpg,png,gif,svg\ndescription=This is a complex description with spaces and special characters: !@#$%^&*()\nwelcome_message=Welcome to \"My App\"\n[database]\nhost=localhost\nport=3306\nuser=dbuser\npassword=s3cr3t\n\n[paths]\ndata_directory=/path/with spaces/data\n\n[logging]\nlevel=info\nfile=/var/log/app.log\nmax_size=10M\n\n"
0 commit comments