Skip to content

Commit 69f5714

Browse files
leaanthonyandreynering
authored andcommitted
fix: disable version check for use as an external library
Closes #1938
1 parent b3e4cfc commit 69f5714

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

cmd/task/task.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ func run() error {
132132
Stdout: os.Stdout,
133133
Stderr: os.Stderr,
134134

135-
OutputStyle: flags.Output,
136-
TaskSorter: taskSorter,
135+
OutputStyle: flags.Output,
136+
TaskSorter: taskSorter,
137+
EnableVersionCheck: true,
137138
}
138139
listOptions := task.NewListOptions(flags.List, flags.ListAll, flags.ListJson, flags.NoStatus)
139140
if err := listOptions.Validate(); err != nil {

setup.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ func (e *Executor) setupConcurrencyState() {
246246
}
247247

248248
func (e *Executor) doVersionChecks() error {
249+
if !e.EnableVersionCheck {
250+
return nil
251+
}
249252
// Copy the version to avoid modifying the original
250253
schemaVersion := &semver.Version{}
251254
*schemaVersion = *e.Taskfile.Version

task.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ type Executor struct {
7070
Stdout io.Writer
7171
Stderr io.Writer
7272

73-
Logger *logger.Logger
74-
Compiler *compiler.Compiler
75-
Output output.Output
76-
OutputStyle ast.Output
77-
TaskSorter sort.TaskSorter
78-
UserWorkingDir string
73+
Logger *logger.Logger
74+
Compiler *compiler.Compiler
75+
Output output.Output
76+
OutputStyle ast.Output
77+
TaskSorter sort.TaskSorter
78+
UserWorkingDir string
79+
EnableVersionCheck bool
7980

8081
fuzzyModel *fuzzy.Model
8182

@@ -383,7 +384,7 @@ func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call *ast.Call,
383384
if err != nil {
384385
return fmt.Errorf("task: failed to get variables: %w", err)
385386
}
386-
stdOut, stdErr, close := outputWrapper.WrapWriter(e.Stdout, e.Stderr, t.Prefix, outputTemplater)
387+
stdOut, stdErr, closer := outputWrapper.WrapWriter(e.Stdout, e.Stderr, t.Prefix, outputTemplater)
387388

388389
err = execext.RunCommand(ctx, &execext.RunCommandOptions{
389390
Command: cmd.Cmd,
@@ -395,7 +396,7 @@ func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call *ast.Call,
395396
Stdout: stdOut,
396397
Stderr: stdErr,
397398
})
398-
if closeErr := close(err); closeErr != nil {
399+
if closeErr := closer(err); closeErr != nil {
399400
e.Logger.Errf(logger.Red, "task: unable to close writer: %v\n", closeErr)
400401
}
401402
if _, isExitError := interp.IsExitStatus(err); isExitError && cmd.IgnoreError {

task_test.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,11 @@ func TestSpecialVars(t *testing.T) {
246246

247247
var buff bytes.Buffer
248248
e := &task.Executor{
249-
Dir: dir,
250-
Stdout: &buff,
251-
Stderr: &buff,
252-
Silent: true,
249+
Dir: dir,
250+
Stdout: &buff,
251+
Stderr: &buff,
252+
Silent: true,
253+
EnableVersionCheck: true,
253254
}
254255
require.NoError(t, e.Setup())
255256
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: test.target}))
@@ -1063,9 +1064,10 @@ func TestTaskVersion(t *testing.T) {
10631064
t.Parallel()
10641065

10651066
e := task.Executor{
1066-
Dir: test.Dir,
1067-
Stdout: io.Discard,
1068-
Stderr: io.Discard,
1067+
Dir: test.Dir,
1068+
Stdout: io.Discard,
1069+
Stderr: io.Discard,
1070+
EnableVersionCheck: true,
10691071
}
10701072
err := e.Setup()
10711073
if test.wantErr {
@@ -2015,9 +2017,10 @@ func TestDisplaysErrorOnVersion1Schema(t *testing.T) {
20152017
t.Parallel()
20162018

20172019
e := task.Executor{
2018-
Dir: "testdata/version/v1",
2019-
Stdout: io.Discard,
2020-
Stderr: io.Discard,
2020+
Dir: "testdata/version/v1",
2021+
Stdout: io.Discard,
2022+
Stderr: io.Discard,
2023+
EnableVersionCheck: true,
20212024
}
20222025
err := e.Setup()
20232026
require.Error(t, err)
@@ -2029,9 +2032,10 @@ func TestDisplaysErrorOnVersion2Schema(t *testing.T) {
20292032

20302033
var buff bytes.Buffer
20312034
e := task.Executor{
2032-
Dir: "testdata/version/v2",
2033-
Stdout: io.Discard,
2034-
Stderr: &buff,
2035+
Dir: "testdata/version/v2",
2036+
Stdout: io.Discard,
2037+
Stderr: &buff,
2038+
EnableVersionCheck: true,
20352039
}
20362040
err := e.Setup()
20372041
require.Error(t, err)

0 commit comments

Comments
 (0)