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

Option or context manager to change directory #1

Closed
pawamoy opened this issue Nov 12, 2020 · 0 comments
Closed

Option or context manager to change directory #1

pawamoy opened this issue Nov 12, 2020 · 0 comments

Comments

@pawamoy
Copy link
Owner

pawamoy commented Nov 12, 2020

Is your feature request related to a problem? Please describe.
I sometimes find myself doing ctx.run("bash -c 'cd dir && actual command'") in order to run a command in another directory.
It's a bit annoying because then it's a shell command and I must quote properly, with the problems that follow.

Describe the solution you'd like
Instead, I'd like to be able to change directory with an option or a context manager:

# with an option
@duty
def task(ctx):
    ctx.run(["actual", "command"], workdir="subfolder")

@duty
def task(ctx):
    with ctx.workdir("subfolder"):
        ctx.run(["actual", "command"])

In fact, we could extrapolate and offer a context manager for all the available options:

@duty
def task(ctx):
    with ctx.options(workdir="subfolder", silent=True):
        ctx.run(["actual", "command"])

Describe alternatives you've considered
The bash -c 'cd && hack.

pawamoy added a commit that referenced this issue Jun 18, 2021
The `workdir` option also comes with a `cd` context manager.
A second context manager is added: `options`.

Issue #1: #1
@pawamoy pawamoy closed this as completed Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant