### PHP: Basic 'Hello World' Command Source: https://github.com/my127/workspace/blob/0.4.x/docs/interpreters/php.md Demonstrates a simple PHP command that outputs 'Hello World'. This is a fundamental example for starting with PHP scripts in the workspace. ```php echo "Hello World"; ``` -------------------------------- ### Hello World Bash Command Example Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md A basic example demonstrating a 'hello world' command implemented in bash. It requires only the usage pattern and the script body, with other elements being optional. ```yaml command('hello world'): | #!bash echo "Hello World" ``` -------------------------------- ### Event Subscription Examples Source: https://context7.com/my127/workspace/llms.txt Illustrates how to subscribe to workspace lifecycle events using `before`, `after`, or `on` prefixes. It shows examples for subscribing to 'harness.install', 'deploy.complete' with environment variables, and triggering custom events using `$ws->trigger()`. ```yaml # Subscribe to harness installation event after('harness.install'): | #!bash echo "Harness installed successfully!" ./scripts/post-install.sh ``` ```yaml # Subscribe with environment variables on('deploy.complete'): env: SLACK_WEBHOOK: = @('slack.webhook') exec: | #!bash curl -X POST -H 'Content-type: application/json' \ --data '{"text":"Deployment completed!"}' \ "${SLACK_WEBHOOK}" ``` ```yaml # Trigger custom events from commands command('deploy'): | #!php // Run deployment logic echo "Starting deployment...\n"; $ws->passthru('./scripts/deploy.sh'); // Trigger custom event $ws->trigger('deploy.complete'); ``` -------------------------------- ### Harness Definition Example Source: https://context7.com/my127/workspace/llms.txt Defines a reusable environment configuration called 'my-web-harness'. It specifies required services, confd templates, and the workspace version compatibility. This allows for consistent environment setup across projects. ```yaml # harness.yml - Define a custom harness harness('my-web-harness'): description: Custom web application harness with proxy support require: services: - proxy - mail confd: - harness:/config workspace: '~0.3' ``` ```yaml # Harness confd templates confd('harness:/config'): - { src: 'docker-compose.yml.twig' } - { src: 'nginx.conf.twig' } ``` -------------------------------- ### Install Workspace CLI Source: https://context7.com/my127/workspace/llms.txt Installs the Workspace CLI tool by downloading the latest release, making it executable, and moving it to the system's PATH. ```bash # Download the latest release curl --output ./ws --location https://github.com/my127/workspace/releases/download/0.3.2/ws # Make executable and move to PATH chmod +x ws && sudo mv ws /usr/local/bin/ws # Verify installation ws --help ``` -------------------------------- ### Example Workspace: Custom Harness Overlay Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/workspace.md Demonstrates how to overlay custom files onto a harness by specifying an overlay directory. ```yaml workspace('acme-ltd'): description: Example description here harness: magento2:latest overlay: tools/workspace ``` -------------------------------- ### Install Workspace CLI Tool Source: https://github.com/my127/workspace/blob/0.4.x/README.md Installs the Workspace command-line interface (CLI) tool by downloading the executable, making it executable, and moving it to a system-wide binary directory. Requires curl and root privileges for moving the file. ```bash curl --output ./ws --location https://github.com/my127/workspace/releases/download/0.3.2/ws chmod +x ws && sudo mv ws /usr/local/bin/ws ``` -------------------------------- ### Twig Configuration Template Example Source: https://context7.com/my127/workspace/llms.txt An example of a Twig template file used for generating a Docker environment file. It demonstrates how to access workspace attributes using the `{{ @('attribute.name') }}` syntax to populate environment variables. ```twig {# config/docker/.env.twig #} DB_HOST={{ @('db.host') }} DB_NAME={{ @('db.name') }} DB_USER={{ @('db.user') }} DB_PASSWORD={{ @('db.password') }} APP_ENV={{ @('environment') }} APP_DEBUG={{ @('app.debug') ? 'true' : 'false' }} ``` -------------------------------- ### Example Workspace: Magento2 Environment Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/workspace.md Sets up a workspace specifically for a Magento2 environment, including a custom namespace. ```yaml workspace('acme-ltd'): description: Example description here harness: magento2:latest attribute('namespace'): my-custom-namespace ``` -------------------------------- ### Manage Workspace Lifecycle with 'ws' Source: https://context7.com/my127/workspace/llms.txt Commands for creating, installing, and managing workspace environments. This includes creating new workspaces with optional harnesses, installing or reinstalling workspaces, and refreshing workspace configurations. Options allow for skipping auto-installation, specific steps, event triggers, and named steps. ```bash # Create a new workspace with optional harness ws create my-app magento2:latest ``` ```bash # Create without auto-installation ws create my-app magento2:latest --no-install ``` ```bash # Install/reinstall workspace (runs harness setup) ws install ``` ```bash # Install specific step only ws install --step=3 ``` ```bash # Install named step ws install --step=prepare ``` ```bash # Skip event triggers during install ws install --skip-events ``` ```bash # Refresh workspace configuration ws refresh ``` -------------------------------- ### Example Workspace: Enforce Version Upgrade Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/workspace.md Configures a workspace to require a specific minimum version of the workspace, useful for enforcing upgrades. ```yaml workspace('acme-upgrade'): description: Example description here require: workspace: '~0.3' ``` -------------------------------- ### PHP: Setting Working Directory for Commands Source: https://github.com/my127/workspace/blob/0.4.x/docs/interpreters/php.md Explains how to specify a working directory for a PHP script using a path prefix like `workspace:/`. The example retrieves and echoes the current working directory. ```php echo getcwd(); ``` -------------------------------- ### Harness for Web Server Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/harness.md Example of a harness declaration for a web server, requiring the 'proxy' service to be available. This allows the harness to be served by Workspace's proxy. ```yaml harness('acme-web-server'): description: Example description here require: services: - proxy ``` -------------------------------- ### Simple Addition Function Example (YAML & Bash) Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/function.md Demonstrates a simple addition function using YAML for declaration and Bash for execution. Arguments are passed and used within the Bash script to perform addition. ```yaml function('add', [v1, v2]): | #!bash ="$((v1+v2))" ``` -------------------------------- ### Declare Subscriber with 'after' Prefix Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/subscriber.md Declares a subscriber that runs a script after a specific event has occurred. The event name is prefixed with 'after.'. This example uses bash to echo a message indicating the harness installation is complete. ```yaml after('harness.install'): | #!bash echo "The harness is now installed." ``` -------------------------------- ### Harness for Workspace Version Upgrade Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/harness.md An example harness that enforces a specific workspace version requirement. This ensures that the project uses a compatible version of the workspace. ```yaml harness('acme-upgrade'): description: Example description here require: workspace: '~0.3' ``` -------------------------------- ### Apply Templates from Config Directory using Command Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/confd.md Applies configuration templates from a specified directory to their destinations using a command. This example demonstrates rendering multiple Twig templates for Docker Compose and Magento configurations. The 'apply()' method is called on the confd object. ```php confd('workspace:/confd'): - { src: 'docker-compose/.env.twig', dst: 'workspace:/.env' } - { src: 'magento/auth.json.twig', dst: 'workspace:/auth.json' } - { src: 'magento/env.php.twig', dst: 'workspace:/app/etc/env.php' } command('apply config'): | #!php $ws->confd('workspace:/confd')->apply(); ``` -------------------------------- ### Retrieve Global Configuration and Power Off Workspace Source: https://context7.com/my127/workspace/llms.txt Fetches configuration values from the global workspace settings and shuts down all running workspace containers. The 'get' command retrieves a specific configuration key, while 'poweroff' terminates all associated Docker containers. ```bash # Retrieve configuration values ws global config get 'db.host' ``` ```bash # Shutdown all workspace containers ws poweroff ``` -------------------------------- ### PHP: Accessing Attributes in Commands Source: https://github.com/my127/workspace/blob/0.4.x/docs/interpreters/php.md Shows how to access pre-defined attributes within a PHP command script using the `$ws` helper. The example retrieves a 'message' attribute and echoes it. ```php echo $ws['message']; ``` -------------------------------- ### Manage Global Services with 'ws global service' Source: https://context7.com/my127/workspace/llms.txt Controls global infrastructure services like Traefik proxy, Mailhog mail service, Elasticsearch/Kibana logger, and Jaeger tracing. Commands include enabling, disabling, restarting, starting, and stopping these services. ```bash # Proxy service (Traefik - handles HTTPS for *.my127.site domains) ws global service proxy enable ws global service proxy restart ws global service proxy disable ``` ```bash # Mail service (Mailhog - captures outbound emails at mail.my127.site) ws global service mail enable ws global service mail disable ``` ```bash # Logger service (Elasticsearch + Kibana stack) ws global service logger enable ws global service logger disable ``` ```bash # Tracing service (Jaeger) ws global service tracing start ws global service tracing stop ``` -------------------------------- ### Define Boolean Command Options Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Handles boolean options in commands. `input.option('option')` returns '1' if the option is present and '' (empty string) otherwise. The example shows manual conversion to 'yes'/'no'. ```yaml command('cmd [--option]'): env: VERBATIM: = input.option('option') YES_OR_NO: = input.option('option') ? 'yes' : 'no' exec: | #!bash echo "'${VERBATIM}'" echo "'${YES_OR_NO}'" ``` -------------------------------- ### Workspace Secret Management Commands Source: https://context7.com/my127/workspace/llms.txt Provides bash commands for managing encrypted secrets. It includes generating a random encryption key, encrypting a secret value, and an example of how to use the encrypted value within the `workspace.yml`. ```bash # Generate a random encryption key ws secret generate-random-key ``` ```bash # Encrypt a secret (use leading space to avoid shell history) ws secret encrypt "my-secret-password" # Output: YTozOntpOjA7czo3OiJkZWZhdWx0Ij... ``` -------------------------------- ### Execute PHP Commands in Workspace Source: https://context7.com/my127/workspace/llms.txt Executes PHP code within the workspace environment. It can call workspace-specific functions like 'add' and 'slugify', or execute shell commands using 'ws->exec'. The execution context can be specified, for example, running PHP from the '/public' directory. ```php $result = $ws->add(100, 50); $slug = $ws->slugify('My Page Title'); echo "Result: {$result}, Slug: {$slug}\n"; ``` ```php $hostname = $ws->exec('hostname'); $uptime = $ws->exec('uptime'); echo "Host: {$hostname}\n"; echo "Uptime: {$uptime}\n"; ``` ```php $files = glob('*.html'); foreach ($files as $file) { echo "Found: {$file}\n"; } ``` -------------------------------- ### PHP Command Execution with Workspace Helper Source: https://context7.com/my127/workspace/llms.txt Demonstrates how to execute commands within the workspace environment using PHP. It showcases the use of the `$ws` helper object to call workspace functions like 'add' and 'greet', and also utilizes the 'slugify' function defined elsewhere. The output is echoed to the console. ```php command('calculate'): | #!php $result = $ws->add(10, 5); echo "10 + 5 = " . $result . "\n"; echo $ws->greet('Developer') . "\n"; echo "Slug: " . $ws->slugify('Hello World Test') . "\n"; ``` -------------------------------- ### Confd Configuration Template Application Source: https://context7.com/my127/workspace/llms.txt Shows how to define and apply configuration file templates using Confd and Twig. It maps Twig template files to their destination paths within the workspace. The 'apply' command then renders these templates into final configuration files. ```php confd('workspace:/config'): - { src: 'docker/.env.twig', dst: 'workspace:/.env' } - { src: 'app/config.php.twig', dst: 'workspace:/app/config.php' } - { src: 'nginx/site.conf.twig', dst: 'workspace:/docker/nginx/site.conf' } ``` ```php command('apply config'): | #!php $ws->confd('workspace:/config')->apply(); echo "Configuration files generated successfully.\n"; ``` -------------------------------- ### Define and Use Standard Attribute in Bash Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/attribute.md Demonstrates how to define a standard attribute 'my.example.message' and then use its value within a bash command using the '@()' syntax for expansion. This is useful for passing dynamic values to scripts. ```yaml attribute('my.example.message'): Hello World command('speak'): | #!bash|@ echo "@('my.example.message')" ``` -------------------------------- ### Call Function with Environment Variable (Bash) Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/function.md Demonstrates calling the 'hello' function within a Bash script. The output of the 'hello' function is then echoed. ```bash command('hi'): | #!bash|= echo "= { hello('World') }" ``` -------------------------------- ### Harness for Confd Rendering Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/harness.md Demonstrates a harness configured for confd rendering. It requires confd blocks to be executed, specifying a template file to be rendered. ```yaml harness('acme-templatable'): description: Example description here require: confd: - harness:/ confd('harness:/'): - src: template.conf ``` -------------------------------- ### PHP Workspace Helper Object Usage Source: https://context7.com/my127/workspace/llms.txt Demonstrates how to interact with workspace functionality from PHP scripts using the `$ws` helper object. It shows accessing attributes via ArrayAccess, invoking other workspace commands, and calling functions. ```php # Access attributes via ArrayAccess command('show-config'): | #!php echo "Database: " . $ws['db.name'] . "\n"; echo "Host: " . $ws['db.host'] . "\n"; ``` ```php # Run other workspace commands command('full-deploy'): | #!php $ws('apply config'); $ws('assets download'); $ws('cache clear'); echo "Deployment complete!\n"; ``` -------------------------------- ### Workspace Configuration (YAML) Source: https://context7.com/my127/workspace/llms.txt Defines a basic workspace configuration in YAML, specifying project name, description, harness package, and overlay settings. It also includes a custom namespace for Docker containers. ```yaml # workspace.yml - Basic workspace configuration workspace('my-project'): description: My web application workspace harness: magento2:latest overlay: tools/workspace require: workspace: '~0.3' # Custom namespace for Docker containers attribute('namespace'): my-custom-namespace ``` -------------------------------- ### Build Workspace Project with Docker Compose Source: https://github.com/my127/workspace/blob/0.4.x/README.md Builds the Workspace project using Docker Compose. This command pulls the latest Docker images and initiates the build process within a Docker environment. It's designed to ensure a consistent build across different systems. ```bash docker-compose build --pull ``` -------------------------------- ### Trigger Custom Event and Respond Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/subscriber.md Demonstrates triggering a custom event named 'my.event' using a bash script and responding to it with a PHP script. The PHP script utilizes the '$ws->trigger()' method to dispatch the custom event. ```yaml on('my.event'): | #!bash echo "This is my custom event." command('hi'): | #!php $ws->trigger('my.event'); ``` -------------------------------- ### Declare Workspace Configuration Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/workspace.md Defines the basic structure for declaring a workspace, including its name, description, harness, overlay, and version requirements. ```yaml workspace('name'): description: Example description here harness: package:version overlay: tools/workspace require: workspace: '~0.3' ``` -------------------------------- ### PHP: Declaring and Calling Functions Source: https://github.com/my127/workspace/blob/0.4.x/docs/interpreters/php.md Illustrates how to declare a PHP function that returns a value and then call it from a command. Functions are declared using the `=` sign for return values on the last line. ```php = "Hello {$name}."; ``` ```php echo $ws->greet('Guest'); ``` -------------------------------- ### Command Definition (YAML) Source: https://context7.com/my127/workspace/llms.txt Shows how to define custom CLI commands in YAML, supporting Bash and PHP interpreters, arguments, options, environment variables, and attribute/expression filters. ```yaml # Simple bash command command('hello world'): | #!bash echo "Hello World" # Command with arguments and options command('deploy [--force]'): description: Deploy application to specified environment env: ENV: = input.argument('environment') FORCE: = input.option('force') ? 'yes' : 'no' exec: | #!bash echo "Deploying to ${ENV} (force: ${FORCE})" ./scripts/deploy.sh "${ENV}" # Command using attributes with @ filter command('assets download'): env: AWS_ID: = @('aws.id') AWS_KEY: = @('aws.key') exec: | #!bash(workspace:/)|@ passthru ws-aws s3 sync @('aws.s3') assets/development # Command with expression filter for complex logic command('backup database'): exec: | #!bash|= mysqldump -h ={ @('db.host') } -u ={ @('db.user') } ={ @('db.name') } > backup.sql # PHP interpreter command command('status'): | #!php echo "Workspace: " . $ws['workspace.name'] . "\n"; echo "Environment: " . $ws['environment'] . "\n"; ``` -------------------------------- ### PHP: Running Other Commands Source: https://github.com/my127/workspace/blob/0.4.x/docs/interpreters/php.md Demonstrates how to execute another declared command from within a PHP command script using the `$ws()` invocation syntax. This allows for command chaining. ```php $ws('hello'); ``` -------------------------------- ### Define Sequence Shortcut for Boolean Options Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Provides a shorthand for defining multiple boolean options in a sequence (e.g., '-iou'). Each option is individually accessible. ```yaml command('cmd [-iou]'): env: OPT_I: = input.option('i') OPT_O: = input.option('o') OPT_U: = input.option('u') ``` -------------------------------- ### Define Value Options for Commands Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Sets up options that expect a value. The value associated with the option is retrieved using `input.option('option')`. ```yaml command('cmd [--option=]'): env: AS_OPTION: = input.option('option') ... ``` -------------------------------- ### Define Command with Selectable Arguments Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Configures arguments that can only accept specific predefined values (e.g., 'on' or 'off'). These arguments work best as the last part of the command and are read using `input.command(index)`. ```yaml command('cmd [on|off]'): env: OPTIONAL_ARG: = input.command(1) command('cmd (on|off])'): env: REQUIRED_ARG: = input.command(1) ``` -------------------------------- ### Function Definition (YAML) Source: https://context7.com/my127/workspace/llms.txt Illustrates defining reusable functions in YAML that can be called from expressions, commands, and scripts. Supports Bash and PHP interpreters, environment variables, and attribute access. ```yaml # Simple addition function in bash function('add', [v1, v2]): | #!bash ="$((v1+v2))" # Function with environment variables function('greet', [name]): env: PREFIX: Hello exec: | #!bash ="${PREFIX} ${name}!" ``` -------------------------------- ### Override Attributes Using Root Object Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/attribute.md Shows how to override multiple attributes, including nested ones like 'db.password', by using the `attributes.override` root object. This provides a structured way to manage overrides. ```yaml attributes.override: db: password: password ``` -------------------------------- ### Define Command with Wildcard Argument (%) Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Allows a command to accept all remaining input as a single argument using the '%' wildcard. This argument must be the last part of the command's usage pattern and is accessed via `input.argument('%')`. ```yaml command('cmd %'): env: ALL: = input.argument('%') exec: | #!bash echo "'${ALL}'" ``` -------------------------------- ### Execute Workspace Build Script in Docker Source: https://github.com/my127/workspace/blob/0.4.x/README.md Executes the build script (`build.sh`) for the Workspace project within a specific Docker container named 'builder83'. This ensures the build process runs in an isolated and controlled environment, using the specified PHP version. ```bash docker-compose exec -u build builder83 /app/build.sh ``` -------------------------------- ### Declare Function with Arguments and Environment Variables (YAML) Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/function.md Defines a function with specified arguments and environment variables. The 'exec' block contains the script to be executed, optionally with an interpreter and filter. A return value can be specified using '='. ```yaml function('name', [arg1, arg2]): env: - NAME: Value exec: | #!interpreter(path:/location)|filter script line 1 script line 2 = return expression ``` -------------------------------- ### Call Addition Function (PHP) Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/function.md Shows how to call the previously defined 'add' function using the PHP interpreter. The result of the function call is then used in a PHP echo statement. ```php command('add'): | #!php echo $ws->add(2, 2) + 2; ``` -------------------------------- ### Declare a Basic Workspace Command Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Defines a simple workspace command with a usage pattern, optional help description, environment variables, and an execution script. The `exec` block specifies the interpreter and the script content. ```yaml command('usage pattern', 'help page'): description: Optional short description, if given, will replace the default "ws " on the help pages env: - NAME: Value exec: | #!interpreter(path:/location)|filter script ``` -------------------------------- ### Attribute Definition (YAML) Source: https://context7.com/my127/workspace/llms.txt Demonstrates defining configuration attributes in YAML, including nested structures, expression-based values using Symfony expressions, and overriding attributes. ```yaml # Define database configuration attributes attribute('db'): driver: mysql host: localhost name: application user: root password: secret # Expression-based attribute using concatenation attribute('db.dsn'): = @('db.driver') ~ ':host=' ~ @('db.host') ~ ';dbname=' ~ @('db.name') # Override attributes in workspace.override.yml (higher precedence) attribute.override('db.password'): production_password # Alternative: Define attributes using root object syntax attributes: aws: s3: s3://my-bucket region: us-east-1 id: AKIAIOSFODNN7EXAMPLE key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY ``` -------------------------------- ### Command Using Expressions with Expression Filter Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Shows how to use the expression filter `|=` for more complex logic within scripts. This allows dynamic construction of script content by embedding expressions that are evaluated before execution. ```yaml attribute('aws'): s3: s3://bucket/path id: my-id-here key: my-key-here command('assets download'): env: AWS_ID: =@('aws.id') AWS_KEY: =@('aws.key') exec: | #!interpreter(workspace:/)|= passthru ws-aws s3 sync ={ @('aws.s3') ~ '/assets/development' } assets/development ``` -------------------------------- ### Declare Harness Block Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/harness.md Defines a harness block with a name and optional description and requirements. The 'require' attribute specifies dependencies like workspace versions. ```yaml harness('name'): description: Example description here require: workspace: '~0.3' ``` -------------------------------- ### Create Attribute Expression for Database DSN Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/attribute.md Illustrates the creation of an attribute 'db.dsn' using a symfony expression that dynamically constructs a database connection string by concatenating values from other attributes ('db.driver', 'db.host', 'db.name'). ```yaml attribute('db'): driver: mysql host: localhost name: application attribute('db.dsn'): = @('db.driver') ~ ':host=' ~ @('db.host') ~ ';dbname=' ~ @('db.name') ``` -------------------------------- ### Define Attribute with Root Object and Use in Bash Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/attribute.md Shows how to define attributes using a nested root object structure and then access them within a bash script. This approach helps in organizing complex attribute definitions. ```yaml attributes: my: example: message: Hello World command('speak'): | #!bash|@ echo "@('my.example.message')" ``` -------------------------------- ### Using Encrypted Secrets in Workspace YAML Source: https://context7.com/my127/workspace/llms.txt Demonstrates how to use encrypted secrets within the `workspace.yml` file. The `decrypt()` function is used to retrieve the secret value at runtime. It also shows a command to display the decrypted secret. ```yaml # workspace.yml - Using encrypted secrets attribute('db.password'): = decrypt('YTozOntpOjA7czo3OiJkZWZhdWx0IjtpOjE7czoyNDoi98rFejkefPnZG1CjzGeFyvSAMgafKv2TIjtpOjI7czoyNzoiSwcG2YiM3vV8CdZXgxDM2q+ZmRmPRNyz7OgcIjt9') ``` ```yaml command('show-password'): | #!bash|@ echo "Password: @('db.password')" ``` -------------------------------- ### Command Using Environment Variables Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Illustrates how to define and use environment variables within a command. The `env` section sets the variable, which can then be accessed within the bash script. ```yaml command('hello from environment'): env: MESSAGE: Hello World exec: | #!bash echo "$MESSAGE" ``` -------------------------------- ### Enable Mail Service Source: https://github.com/my127/workspace/blob/0.4.x/docs/cheatsheet.md Enables the mail service, which is not running by default. Once enabled, emails can be viewed at https://mail.my127.site/. This service allows email collection via native sendmail. ```bash ws global service mail enable ``` -------------------------------- ### Declare Configuration Directory with Twig Templates Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/confd.md Declares a directory as a source for configuration files to be rendered by the Twig template engine. It maps source template files (relative to the declared directory) to their destination paths. Any attributes and functions are accessible within the Twig templates. ```text confd('path:/directory'): - { src: 'template.twig', dst: 'path:/file' } ``` -------------------------------- ### Encrypt and Decrypt Workspace Secret Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/crypt.md Demonstrates encrypting a secret value using `ws secret encrypt` and then decrypting it within a workspace configuration file using the `decrypt()` function. It's crucial to prevent secrets from entering shell history. ```shell >>> ws secret encrypt "Hello World" YTozOntpOjA7czo3OiJkZWZhdWx0IjtpOjE7czoyNDoi98rFejkefPnZG1CjzGeFyvSAMgafKv2TIjtpOjI7czoyNzoiSwcG2YiM3vV8CdZXgxDM2q+ZmRmPRNyz7OgcIjt9 workspace.yml: attribute('message'): = decrypt('YTozOntpOjA7czo3OiJkZWZhdWx0IjtpOjE7czoyNDoi98rFejkefPnZG1CjzGeFyvSAMgafKv2TIjtpOjI7czoyNzoiSwcG2YiM3vV8CdZXgxDM2q+ZmRmPRNyz7OgcIjt9') command('hello'): | #!bash|@ echo "@('message')" >>> ws hello Hello World ``` -------------------------------- ### Command Executed from Specific Path Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Ensures a command is executed from a specific directory within the workspace, such as the root. This is achieved by specifying the path in the interpreter directive (e.g., `#!bash(workspace:/)`). ```yaml command('ls'): | #!bash(workspace:/) ls ``` -------------------------------- ### Fix Docker Volume Permissions for Linux Source: https://github.com/my127/workspace/blob/0.4.x/README.md Sets the `HOST_OS_FAMILY` environment variable to 'linux' to ensure correct Docker volume permissions when running Docker Compose on a Linux system. This is often necessary to avoid permission issues with mounted volumes. ```bash HOST_OS_FAMILY=linux docker-compose up -d ``` -------------------------------- ### Fix Docker Volume Permissions for macOS Source: https://github.com/my127/workspace/blob/0.4.x/README.md Sets the `HOST_OS_FAMILY` environment variable to 'darwin' to ensure correct Docker volume permissions when running Docker Compose on a macOS system. This helps manage file ownership and access for Docker volumes. ```bash HOST_OS_FAMILY=darwin docker-compose up -d ``` -------------------------------- ### Function with Environment Variable and Argument (YAML & Bash) Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/function.md Illustrates defining a function that utilizes both an environment variable ('MESSAGE') and a passed argument ('v1'). The Bash script concatenates these to form the output. ```yaml function('hello', [v1]): env: MESSAGE: Hello exec: | #!bash ="${MESSAGE} ${v1}" ``` -------------------------------- ### Secret Encryption Key Configuration Source: https://context7.com/my127/workspace/llms.txt Defines the encryption key for secret management within the `workspace.override.yml` file. This file should be gitignored to protect sensitive keys. The 'default' key is specified here. ```yaml # workspace.override.yml (gitignored - contains encryption keys) key('default'): 81a7fa14a8ceb8e1c8860031e2bac03f4b939de44fa1a78987a3fcff1bf57100 ``` -------------------------------- ### Define Command Arguments (Required and Optional) Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Specifies required and optional arguments for a command. The command will not be recognized without the required arguments. Arguments are accessed via `input.argument()` and can be used in environment variables and the execution script. ```yaml command('cmd []'): env: REQUIRED: = input.argument('required') OPTIONAL: = input.argument('optional') exec: | #!bash echo "'${REQUIRED}'" echo "'${OPTIONAL}'" ``` -------------------------------- ### Declare Subscriber with Environment Variables Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/subscriber.md Declares a subscriber that listens for a specific event. It allows setting environment variables for the script execution and specifies the script to run. The interpreter and filter can be defined within the script directive. ```yaml on('event.name'): env: NAME: Value exec: | #!interpreter(path:/location)|filter script ``` -------------------------------- ### Define Mutually Exclusive Command Options Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Allows defining mutually exclusive options, including support for long and short form alternatives. Both forms need to be checked explicitly as they are treated as distinct options by the parser. ```yaml command('cmd [-b|--bool] [-s=|--string=]'): env: BOOL_OPTION: = input.option('bool') || input.option('b') VALUE_OPTION: = input.option('string') ?: input.option('s') exec: | #!bash echo "'${BOOL_OPTION}'" echo "'${VALUE_OPTION}'" ``` -------------------------------- ### Override Attribute Value Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/attribute.md Demonstrates how to override the value of an existing attribute, specifically 'db.password', using the `attribute.override` method. This is useful for setting sensitive information or specific configurations. ```yaml attribute.override('db.password'): password ``` -------------------------------- ### Restart Traefik Proxy Service Source: https://github.com/my127/workspace/blob/0.4.x/docs/cheatsheet.md Restarts the Traefik proxy service to resolve issues, such as invalid SSL certificates. This command directly interacts with the global service management. ```bash ws global service proxy restart ``` -------------------------------- ### Command Leveraging Attributes with Attribute Filter Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/command.md Demonstrates using the attribute filter `|@` to inject values from defined attributes directly into a script before execution. This is useful for passing configuration or secrets. ```yaml attribute('aws'): s3: s3://bucket id: my-id-here key: my-key-here command('assets download'): env: AWS_ID: =@('aws.id') AWS_KEY: =@('aws.key') exec: | #!interpreter(workspace:/)|@ passthru ws-aws s3 sync @('aws.s3') assets/development ``` -------------------------------- ### PHP String Manipulation: Slugify Function Source: https://context7.com/my127/workspace/llms.txt Defines a PHP function 'slugify' that converts a given text into a URL-friendly slug by converting it to lowercase and replacing non-alphanumeric characters with hyphens. This function is useful for generating slugs for URLs or file names. ```php function('slugify', [text]): | #!php = strtolower(preg_replace('/[^a-z0-9]+/i', '-', $text)); ``` -------------------------------- ### Declare Encryption Key Source: https://github.com/my127/workspace/blob/0.4.x/docs/types/crypt.md Declares a key used for encrypting and decrypting workspace secrets. The `default` key is auto-generated or can be manually set using a random key. ```yaml key('default'): 81a7fa14a8ceb8e1c8860031e2bac03f4b939de44fa1a78987a3fcff1bf57100 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.