mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
refactor: move prompts into consts
This commit is contained in:
@@ -15,6 +15,15 @@ import (
|
|||||||
"github.com/go-task/task/v3/taskfile/ast"
|
"github.com/go-task/task/v3/taskfile/ast"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
taskfileUntrustedPrompt = `The task you are attempting to run depends on the remote Taskfile at %q.
|
||||||
|
--- Make sure you trust the source of this Taskfile before continuing ---
|
||||||
|
Continue?`
|
||||||
|
taskfileChangedPrompt = `The Taskfile at %q has changed since you last used it!
|
||||||
|
--- Make sure you trust the source of this Taskfile before continuing ---
|
||||||
|
Continue?`
|
||||||
|
)
|
||||||
|
|
||||||
// Read reads a Read for a given directory
|
// Read reads a Read for a given directory
|
||||||
// Uses current dir when dir is left empty. Uses Read.yml
|
// Uses current dir when dir is left empty. Uses Read.yml
|
||||||
// or Read.yaml when entrypoint is left empty
|
// or Read.yaml when entrypoint is left empty
|
||||||
@@ -221,19 +230,17 @@ func readTaskfile(
|
|||||||
checksum := checksum(b)
|
checksum := checksum(b)
|
||||||
cachedChecksum := cache.readChecksum(node)
|
cachedChecksum := cache.readChecksum(node)
|
||||||
|
|
||||||
var msg string
|
var prompt string
|
||||||
if cachedChecksum == "" {
|
if cachedChecksum == "" {
|
||||||
// If the checksum doesn't exist, prompt the user to continue
|
// If the checksum doesn't exist, prompt the user to continue
|
||||||
msg = fmt.Sprintf("The task you are attempting to run depends on the remote Taskfile at %q.\n--- Make sure you trust the source of this Taskfile before continuing ---\nContinue?", node.Location())
|
prompt = fmt.Sprintf(taskfileUntrustedPrompt, node.Location())
|
||||||
} else if checksum != cachedChecksum {
|
} else if checksum != cachedChecksum {
|
||||||
// If there is a cached hash, but it doesn't match the expected hash, prompt the user to continue
|
// If there is a cached hash, but it doesn't match the expected hash, prompt the user to continue
|
||||||
msg = fmt.Sprintf("The Taskfile at %q has changed since you last used it!\n--- Make sure you trust the source of this Taskfile before continuing ---\nContinue?", node.Location())
|
prompt = fmt.Sprintf(taskfileChangedPrompt, node.Location())
|
||||||
}
|
}
|
||||||
if msg != "" {
|
if prompt == "" {
|
||||||
if err := l.Prompt(logger.Yellow, msg, "n", "y", "yes"); errors.Is(err, logger.ErrPromptCancelled) {
|
if err := l.Prompt(logger.Yellow, prompt, "n", "y", "yes"); err != nil {
|
||||||
return nil, &errors.TaskfileNotTrustedError{URI: node.Location()}
|
return nil, &errors.TaskfileNotTrustedError{URI: node.Location()}
|
||||||
} else if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user