Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--unsafe and --compose flags for config env command #853

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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