mirror of
https://github.com/go-task/task.git
synced 2025-02-07 13:41:53 +02:00
feat: add TASK_OFFLINE env and expose it as a special variable (#1716)
Co-authored-by: Pete Davison <pd93.uk@outlook.com>
This commit is contained in:
parent
96a690ac2f
commit
ddccd1bb61
@ -198,6 +198,7 @@ func run() error {
|
||||
globals.Set("CLI_FORCE", ast.Var{Value: flags.Force || flags.ForceAll})
|
||||
globals.Set("CLI_SILENT", ast.Var{Value: flags.Silent})
|
||||
globals.Set("CLI_VERBOSE", ast.Var{Value: flags.Verbose})
|
||||
globals.Set("CLI_OFFLINE", ast.Var{Value: flags.Offline})
|
||||
e.Taskfile.Vars.Merge(globals, nil)
|
||||
|
||||
if !flags.Watch {
|
||||
|
@ -1,9 +1,11 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
@ -77,7 +79,10 @@ func init() {
|
||||
log.Print(usage)
|
||||
pflag.PrintDefaults()
|
||||
}
|
||||
|
||||
offline, err := strconv.ParseBool(cmp.Or(os.Getenv("TASK_OFFLINE"), "false"))
|
||||
if err != nil {
|
||||
offline = false
|
||||
}
|
||||
pflag.BoolVar(&Version, "version", false, "Show Task version.")
|
||||
pflag.BoolVarP(&Help, "help", "h", false, "Shows Task usage.")
|
||||
pflag.BoolVarP(&Init, "init", "i", false, "Creates a new Taskfile.yml in the current folder.")
|
||||
@ -120,7 +125,7 @@ func init() {
|
||||
// Remote Taskfiles experiment will adds the "download" and "offline" flags
|
||||
if experiments.RemoteTaskfiles.Enabled {
|
||||
pflag.BoolVar(&Download, "download", false, "Downloads a cached version of a remote Taskfile.")
|
||||
pflag.BoolVar(&Offline, "offline", false, "Forces Task to only use local or cached Taskfiles.")
|
||||
pflag.BoolVar(&Offline, "offline", offline, "Forces Task to only use local or cached Taskfiles.")
|
||||
pflag.DurationVar(&Timeout, "timeout", time.Second*10, "Timeout for downloading remote Taskfiles.")
|
||||
pflag.BoolVar(&ClearCache, "clear-cache", false, "Clear the remote cache.")
|
||||
}
|
||||
|
@ -8,16 +8,17 @@ sidebar_position: 4
|
||||
Task allows you to configure some behavior using environment variables. This
|
||||
page lists all the environment variables that Task supports.
|
||||
|
||||
| ENV | Default | Description |
|
||||
| ----------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `TASK_TEMP_DIR` | `.task` | Location of the temp dir. Can relative to the project like `tmp/task` or absolute like `/tmp/.task` or `~/.task`. |
|
||||
| `TASK_REMOTE_DIR` | `TASK_TEMP_DIR` | Location of the remote temp dir (used for caching). Can relative to the project like `tmp/task` or absolute like `/tmp/.task` or `~/.task`. |
|
||||
| `FORCE_COLOR` | | Force color output usage. |
|
||||
| ENV | Default | Description |
|
||||
|-------------------|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `TASK_TEMP_DIR` | `.task` | Location of the temp dir. Can relative to the project like `tmp/task` or absolute like `/tmp/.task` or `~/.task`. |
|
||||
| `TASK_REMOTE_DIR` | `TASK_TEMP_DIR` | Location of the remote temp dir (used for caching). Can relative to the project like `tmp/task` or absolute like `/tmp/.task` or `~/.task`. |
|
||||
| `TASK_OFFLINE` | `false` | Set the `--offline` flag through the environment variable. Only for remote experiment. CLI flag `--offline` takes precedence over the env variable |
|
||||
| `FORCE_COLOR` | | Force color output usage. |
|
||||
|
||||
## Custom Colors
|
||||
|
||||
| ENV | Default | Description |
|
||||
| --------------------------- | ------- | ----------------------- |
|
||||
|-----------------------------|---------|-------------------------|
|
||||
| `TASK_COLOR_RESET` | `0` | Color used for white. |
|
||||
| `TASK_COLOR_RED` | `31` | Color used for red. |
|
||||
| `TASK_COLOR_GREEN` | `32` | Color used for green. |
|
||||
|
@ -106,6 +106,7 @@ special variable will be overridden.
|
||||
| `CLI_FORCE` | A boolean containing whether the `--force` or `--force-all` flags were set. |
|
||||
| `CLI_SILENT` | A boolean containing whether the `--silent` flag was set. |
|
||||
| `CLI_VERBOSE` | A boolean containing whether the `--verbose` flag was set. |
|
||||
| `CLI_OFFLINE` | A boolean containing whether the `--offline` flag was set. |
|
||||
| `TASK` | The name of the current task. |
|
||||
| `ALIAS` | The alias used for the current task, otherwise matches `TASK`. |
|
||||
| `TASK_EXE` | The Task executable name or path. |
|
||||
|
Loading…
x
Reference in New Issue
Block a user