Skip to content

Commit

Permalink
--unsafe and --compose flags for config env command (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout authored Oct 20, 2023
1 parent 02a26cd commit e9c9916
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
24 changes: 19 additions & 5 deletions src/dipdup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e9c9916

Please sign in to comment.