-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds requires conditions for task
json environments are full featured now with `default`, `required`, and templated values
- Loading branch information
1 parent
d4fad9a
commit 5bc0617
Showing
10 changed files
with
537 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
Github Issue: https://github.com/nxtcoder17/Runfile/issues/8 | ||
--- | ||
|
||
### Expectations from this implementation ? | ||
|
||
I would like to be able to do stuffs like: | ||
- whether these environment variables have been defined | ||
- whether this filepath exists or not | ||
- whether `this command` or script runs sucessfully | ||
|
||
And, when answers to these questsions are `true`, then only run the target, otherwise throw the errors | ||
|
||
### Problems with Taskfile.dev implementation | ||
|
||
They have 2 ways to tackle this, with | ||
|
||
- `requires`: but, it works with vars only, ~no environment variables~ | ||
|
||
- `preconditions`: test conditions must be a valid linux `test` command, which assumes everyone knows how to read bash's `test` or `if` statements | ||
|
||
|
||
### My Approach | ||
|
||
1. Support for `test` commands, must be there, for advanced users | ||
|
||
2. But, for simpler use cases, there should be alternate ways to do it, something that whole team just understands. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package errors | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type Context struct { | ||
Task string | ||
Runfile string | ||
|
||
message *string | ||
err error | ||
} | ||
|
||
func (c Context) WithMessage(msg string) Context { | ||
c.message = &msg | ||
return c | ||
} | ||
|
||
func (c Context) WithErr(err error) Context { | ||
c.err = err | ||
return c | ||
} | ||
|
||
func (c Context) ToString() string { | ||
m := map[string]string{ | ||
"task": c.Task, | ||
"runfile": c.Runfile, | ||
} | ||
if c.message != nil { | ||
m["message"] = *c.message | ||
} | ||
|
||
if c.err != nil { | ||
m["err"] = c.err.Error() | ||
} | ||
|
||
b, err := json.Marshal(m) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return string(b) | ||
} | ||
|
||
func (e Context) Error() string { | ||
return e.ToString() | ||
} | ||
|
||
type ( | ||
ErrTaskInvalid struct{ Context } | ||
) | ||
|
||
type ErrTaskFailedRequirements struct { | ||
Context | ||
Requirement string | ||
} | ||
|
||
func (e ErrTaskFailedRequirements) Error() string { | ||
if e.message == nil { | ||
e.Context = e.Context.WithMessage(fmt.Sprintf("failed (requirement: %q)", e.Requirement)) | ||
} | ||
return e.Context.Error() | ||
} | ||
|
||
type TaskNotFound struct { | ||
Context | ||
} | ||
|
||
func (e TaskNotFound) Error() string { | ||
// return fmt.Sprintf("[task] %s, not found in [Runfile] at %s", e.TaskName, e.RunfilePath) | ||
if e.message == nil { | ||
e.Context = e.Context.WithMessage("Not Found") | ||
} | ||
return e.Context.Error() | ||
} | ||
|
||
type ErrTaskGeneric struct { | ||
Context | ||
} | ||
|
||
type InvalidWorkingDirectory struct { | ||
Context | ||
} | ||
|
||
func (e InvalidWorkingDirectory) Error() string { | ||
// return fmt.Sprintf("[task] %s, not found in [Runfile] at %s", e.TaskName, e.RunfilePath) | ||
if e.message == nil { | ||
e.Context = e.Context.WithMessage("Invalid Working Directory") | ||
} | ||
return e.Context.Error() | ||
} | ||
|
||
type InvalidDotEnv struct { | ||
Context | ||
} | ||
|
||
func (e InvalidDotEnv) Error() string { | ||
if e.message == nil { | ||
e.Context = e.Context.WithMessage("invalid dotenv") | ||
} | ||
return e.Context.Error() | ||
} | ||
|
||
type InvalidEnvVar struct { | ||
Context | ||
} | ||
|
||
func (e InvalidEnvVar) Error() string { | ||
if e.message == nil { | ||
e.Context = e.Context.WithMessage("invalid dotenv") | ||
} | ||
return e.Context.Error() | ||
} | ||
|
||
type IncorrectCommand struct { | ||
Context | ||
} | ||
|
||
func (e IncorrectCommand) Error() string { | ||
if e.message == nil { | ||
e.Context = e.Context.WithMessage("incorrect command") | ||
} | ||
return e.Context.Error() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.