diff --git a/CHANGELOG.md b/CHANGELOG.md index b605e6df5..a9e25bf27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic ### Added +- cli: Added `--unsafe` and `--compose` flags to `config env` command. - cli: Relative paths to be initialized now can be passed to the `init` command as arguments. - tezos.tzkt.token_balances: Added new index. diff --git a/src/dipdup/cli.py b/src/dipdup/cli.py index 86223390e..bb35be168 100644 --- a/src/dipdup/cli.py +++ b/src/dipdup/cli.py @@ -362,20 +362,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: