Run command with environment variables present.
(ctx: click.Context, override: bool, commandline: List[str])
| 145 | ) |
| 146 | @click.argument('commandline', nargs=-1, type=click.UNPROCESSED) |
| 147 | def run(ctx: click.Context, override: bool, commandline: List[str]) -> None: |
| 148 | """Run command with environment variables present.""" |
| 149 | file = ctx.obj['FILE'] |
| 150 | if not os.path.isfile(file): |
| 151 | raise click.BadParameter( |
| 152 | f'Invalid value for \'-f\' "{file}" does not exist.', |
| 153 | ctx=ctx |
| 154 | ) |
| 155 | dotenv_as_dict = { |
| 156 | k: v |
| 157 | for (k, v) in dotenv_values(file).items() |
| 158 | if v is not None and (override or k not in os.environ) |
| 159 | } |
| 160 | |
| 161 | if not commandline: |
| 162 | click.echo('No command given.') |
| 163 | exit(1) |
| 164 | ret = run_command(commandline, dotenv_as_dict) |
| 165 | exit(ret) |
| 166 | |
| 167 | |
| 168 | def run_command(command: List[str], env: Dict[str, str]) -> int: |
nothing calls this directly
no test coverage detected