MCPcopy Create free account
hub / github.com/theskumar/python-dotenv / run

Function run

src/dotenv/cli.py:147–165  ·  view source on GitHub ↗

Run command with environment variables present.

(ctx: click.Context, override: bool, commandline: List[str])

Source from the content-addressed store, hash-verified

145)
146@click.argument('commandline', nargs=-1, type=click.UNPROCESSED)
147def 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
168def run_command(command: List[str], env: Dict[str, str]) -> int:

Callers

nothing calls this directly

Calls 2

dotenv_valuesFunction · 0.85
run_commandFunction · 0.85

Tested by

no test coverage detected