Skip to content

Commit

Permalink
--unsafe and --compose flags to config env command
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Sep 29, 2023
1 parent 513e3af commit 8e625b2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning].

## [Unreleased]

### Added

- cli: Added `--unsafe` and `--compose` flags to `config env` command.

## [7.0.0] - 2023-09-25

### Fixed
Expand Down
24 changes: 19 additions & 5 deletions src/dipdup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,20 +344,34 @@ async def config_export(ctx: click.Context, unsafe: bool, full: bool) -> None:

@config.command(name='env')
@click.option('--output', '-o', type=str, default=None, help='Output to file instead of stdout.')
@click.option('--unsafe', is_flag=True, help='Resolve environment variables or use default values from the config.')
@click.option('--compose', is_flag=True, help='Output in docker-compose format.')
@click.pass_context
@_cli_wrapper
async def config_env(ctx: click.Context, output: str | None) -> None:
async def config_env(ctx: click.Context, output: str | None, unsafe: bool, compose: bool) -> None:
"""Dump environment variables used in DipDup config.
If variable is not set, default value will be used.
"""
from dipdup.config import DipDupConfig
from dipdup.yaml import DipDupYAMLConfig

config = DipDupConfig.load(
config, environment = DipDupYAMLConfig.load(
paths=ctx.obj.config._paths,
environment=True,
environment=unsafe,
)
content = '\n'.join(f'{k}={v}' for k, v in sorted(config._environment.items()))
if compose:
content = '\nservices:\n dipdup:\n environment:\n'
_tab = ' ' * 6
for k, v in sorted(environment.items()):
line = f'{_tab}- {k}=' + '${' + k
if v:
line += ':-' + v + '}'
else:
line += '}'

content += line + '\n'
else:
content = '\n'.join(f'{k}={v}' for k, v in sorted(environment.items()))
if output:
Path(output).write_text(content)
else:
Expand Down

0 comments on commit 8e625b2

Please sign in to comment.