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

Feature Request: provide a bool variable to tasks that represents if the —offline flag is used #1470

Closed
wburningham opened this issue Jan 13, 2024 · 6 comments · Fixed by #1716
Labels
area: remote Changes related to remote taskfiles. type: feature A new feature or functionality.

Comments

@wburningham
Copy link

My company is working on moving over to taskfiles for 200+ builds/apps/libraries. We rely on remote taskfiles to deduplicate build scripts. We’d like to execute logic based on whether or not a consumer uses the —offline flag.

Examples:

  1. prevent a task from running if using offline mode. Certain tasks require the latest remote taskfiles
  2. If offline disable commands in tasks that would make HTTP requests (docker pull)
  3. Prompt a user for confirmation before running tasks that could benefit from pulling the latest remote taskfile
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Jan 13, 2024
@vmaerten vmaerten added type: feature A new feature or functionality. area: remote Changes related to remote taskfiles. and removed state: needs triage Waiting to be triaged by a maintainer. labels Jun 30, 2024
@mgbowman
Copy link

What's the expected behavior for...

export TASK_OFFLINE="1"
task --download --yes

I think what will happen is ...

task: You can't set both --download and --offline flags

IMHO, in the presence of both --download and --offline, the --offline flag should be ignored (maybe print a info/warning message). As --download is a nop by design (it only downloads remote files, it doesn't execute a task), seems reasonable to me.

My use case is to always run taskoffline unless it's been told to download the remote taskfiles.

Thoughts?

@pd93
Copy link
Member

pd93 commented Sep 20, 2024

@mgbowman if I set a flag (or env var) that tells Task to be offline, my expectation is that it will never connect to the internet. I don't think another flag should be able to override this. Since download contradicts this, the combination is a not allowed.

@mgbowman
Copy link

Totally get where you're coming from, the two options are in-fact mutually exclusive.

My previous comment was based on some CLIs I've seen that will ignore mutually exclusive options when it's trivial to interpret what the user meant to do. For example, running task --download --offline does not make any logical sense, so I feel it would be "safe" to ignore the --offline flag

I guess this would work for me...

export TASK_OFFLINE="1"
TASK_OFFLINE="" task --download --yes

The use case being TASK_OFFLINE=1 will always be set, by my devs, in my docker images, in my pipelines, but I still need to "bootstrap" by downloading the remote taskfiles.

@pd93
Copy link
Member

pd93 commented Sep 20, 2024

How about allowing --offline=false on the CLI to override TASK_OFFLINE? This is much more explicit and allows for your use case. @vmaerten thoughts since you have an active PR?

@mgbowman
Copy link

mgbowman commented Sep 20, 2024

If the cli arg overrides the env var then absolutely yes!

This works with v3.39.2

$ alias tasko='task --offline' # poor man's TASK_OFFLINE=1
$ tasko --offline=false --download --yes
The task you are attempting to run depends on the remote Taskfile at ...

@vmaerten
Copy link
Member

vmaerten commented Sep 20, 2024

How about allowing --offline=false on the CLI to override TASK_OFFLINE? This is much more explicit and allows for your use case. @vmaerten thoughts since you have an active PR?

I totally agree and, in my PR, it already works like that :

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: remote Changes related to remote taskfiles. type: feature A new feature or functionality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants