Skip to content

Commit 9e902a5

Browse files
committed
feat(flags): add env var support for dry, yes, and silent flags
Add environment variable configuration for three CLI flags: - TASK_DRY: enable dry-run mode without executing tasks - TASK_ASSUME_YES: automatically answer yes to prompts - TASK_SILENT: disable command echoing (also supports taskrc config) The silent flag gets full support with both taskrc configuration and environment variable, while dry and yes are env-var only.
1 parent 7f3cc34 commit 9e902a5

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

internal/flags/flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ func init() {
129129
pflag.BoolVar(&Insecure, "insecure", getConfig(config, "REMOTE_INSECURE", func() *bool { return config.Remote.Insecure }, false), "Forces Task to download Taskfiles over insecure connections.")
130130
pflag.BoolVarP(&Watch, "watch", "w", false, "Enables watch of the given task.")
131131
pflag.BoolVarP(&Verbose, "verbose", "v", getConfig(config, "VERBOSE", func() *bool { return config.Verbose }, false), "Enables verbose mode.")
132-
pflag.BoolVarP(&Silent, "silent", "s", false, "Disables echoing.")
132+
pflag.BoolVarP(&Silent, "silent", "s", getConfig(config, "SILENT", func() *bool { return config.Silent }, false), "Disables echoing.")
133133
pflag.BoolVar(&DisableFuzzy, "disable-fuzzy", getConfig(config, "DISABLE_FUZZY", func() *bool { return config.DisableFuzzy }, false), "Disables fuzzy matching for task names.")
134-
pflag.BoolVarP(&AssumeYes, "yes", "y", false, "Assume \"yes\" as answer to all prompts.")
134+
pflag.BoolVarP(&AssumeYes, "yes", "y", getConfig(config, "ASSUME_YES", func() *bool { return nil }, false), "Assume \"yes\" as answer to all prompts.")
135135
pflag.BoolVarP(&Parallel, "parallel", "p", false, "Executes tasks provided on command line in parallel.")
136-
pflag.BoolVarP(&Dry, "dry", "n", false, "Compiles and prints tasks in the order that they would be run, without executing them.")
136+
pflag.BoolVarP(&Dry, "dry", "n", getConfig(config, "DRY", func() *bool { return nil }, false), "Compiles and prints tasks in the order that they would be run, without executing them.")
137137
pflag.BoolVar(&Summary, "summary", false, "Show summary about a task.")
138138
pflag.BoolVarP(&ExitCode, "exit-code", "x", false, "Pass-through the exit code of the task command.")
139139
pflag.StringVarP(&Dir, "dir", "d", "", "Sets the directory in which Task will execute and look for a Taskfile.")

taskrc/ast/taskrc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
type TaskRC struct {
1313
Version *semver.Version `yaml:"version"`
1414
Verbose *bool `yaml:"verbose"`
15+
Silent *bool `yaml:"silent"`
1516
Color *bool `yaml:"color"`
1617
DisableFuzzy *bool `yaml:"disable-fuzzy"`
1718
Concurrency *int `yaml:"concurrency"`
@@ -56,6 +57,7 @@ func (t *TaskRC) Merge(other *TaskRC) {
5657
}
5758

5859
t.Verbose = cmp.Or(other.Verbose, t.Verbose)
60+
t.Silent = cmp.Or(other.Silent, t.Silent)
5961
t.Color = cmp.Or(other.Color, t.Color)
6062
t.DisableFuzzy = cmp.Or(other.DisableFuzzy, t.DisableFuzzy)
6163
t.Concurrency = cmp.Or(other.Concurrency, t.Concurrency)

website/src/docs/reference/cli.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ task build --verbose
107107

108108
Disable command echoing.
109109

110+
- **Config equivalent**: [`silent`](./config.md#silent)
111+
- **Environment variable**: [`TASK_SILENT`](./environment.md#task-silent)
112+
110113
```bash
111114
task deploy --silent
112115
```
@@ -149,6 +152,8 @@ task build --force
149152

150153
Compile and print tasks without executing them.
151154

155+
- **Environment variable**: [`TASK_DRY`](./environment.md#task-dry)
156+
152157
```bash
153158
task deploy --dry
154159
```
@@ -312,6 +317,8 @@ task build --watch --interval 1s
312317

313318
Automatically answer "yes" to all prompts.
314319

320+
- **Environment variable**: [`TASK_ASSUME_YES`](./environment.md#task-assume-yes)
321+
315322
```bash
316323
task deploy --yes
317324
```

website/src/docs/reference/config.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ experiments:
9292
verbose: true
9393
```
9494

95+
### `silent`
96+
97+
- **Type**: `boolean`
98+
- **Default**: `false`
99+
- **Description**: Disables echoing of commands
100+
- **CLI equivalent**: [`-s, --silent`](./cli.md#-s---silent)
101+
- **Environment variable**: [`TASK_SILENT`](./environment.md#task-silent)
102+
103+
```yaml
104+
silent: true
105+
```
106+
95107
### `color`
96108

97109
- **Type**: `boolean`
@@ -147,6 +159,7 @@ Here's a complete example of a `.taskrc.yml` file with all available options:
147159
```yaml
148160
# Global settings
149161
verbose: true
162+
silent: false
150163
color: true
151164
disable-fuzzy: false
152165
concurrency: 2

website/src/docs/reference/environment.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ variables. The priority order is: CLI flags > environment variables > config fil
2929
- **Description**: Enable verbose output for all tasks
3030
- **Config equivalent**: [`verbose`](./config.md#verbose)
3131

32+
### `TASK_SILENT`
33+
34+
- **Type**: `boolean` (`true`, `false`, `1`, `0`)
35+
- **Default**: `false`
36+
- **Description**: Disables echoing of commands
37+
- **Config equivalent**: [`silent`](./config.md#silent)
38+
3239
### `TASK_COLOR`
3340

3441
- **Type**: `boolean` (`true`, `false`, `1`, `0`)
@@ -56,6 +63,18 @@ variables. The priority order is: CLI flags > environment variables > config fil
5663
- **Description**: When running tasks in parallel, stop all tasks if one fails
5764
- **Config equivalent**: [`failfast`](./config.md#failfast)
5865

66+
### `TASK_DRY`
67+
68+
- **Type**: `boolean` (`true`, `false`, `1`, `0`)
69+
- **Default**: `false`
70+
- **Description**: Compiles and prints tasks in the order that they would be run, without executing them
71+
72+
### `TASK_ASSUME_YES`
73+
74+
- **Type**: `boolean` (`true`, `false`, `1`, `0`)
75+
- **Default**: `false`
76+
- **Description**: Assume "yes" as answer to all prompts
77+
5978
### `TASK_TEMP_DIR`
6079

6180
Defines the location of Task's temporary directory which is used for storing

website/src/public/schema-taskrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
"type": "boolean",
6262
"description": "Enable verbose output"
6363
},
64+
"silent": {
65+
"type": "boolean",
66+
"description": "Disables echoing",
67+
"default": false
68+
},
6469
"color": {
6570
"type": "boolean",
6671
"description": "Enable colored output"

0 commit comments

Comments
 (0)