Run command with environment variables present.
(ctx: click.Context, override: bool, commandline: tuple[str, ...])
| 182 | ) |
| 183 | @click.argument("commandline", nargs=-1, type=click.UNPROCESSED) |
| 184 | def run(ctx: click.Context, override: bool, commandline: tuple[str, ...]) -> None: |
| 185 | """Run command with environment variables present.""" |
| 186 | file = ctx.obj["FILE"] |
| 187 | if not os.path.isfile(file): |
| 188 | raise click.BadParameter( |
| 189 | f"Invalid value for '-f' \"{file}\" does not exist.", ctx=ctx |
| 190 | ) |
| 191 | dotenv_as_dict = { |
| 192 | k: v |
| 193 | for (k, v) in dotenv_values(file).items() |
| 194 | if v is not None and (override or k not in os.environ) |
| 195 | } |
| 196 | |
| 197 | if not commandline: |
| 198 | click.echo("No command given.") |
| 199 | sys.exit(1) |
| 200 | |
| 201 | run_command([*commandline, *ctx.args], dotenv_as_dict) |
| 202 | |
| 203 | |
| 204 | def run_command(command: List[str], env: Dict[str, str]) -> None: |
nothing calls this directly
no test coverage detected