-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mathieu Frenette <[email protected]>
- Loading branch information
Showing
8 changed files
with
98 additions
and
7 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
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
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,41 @@ | ||
package steps | ||
|
||
import ( | ||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/Samasource/jen/src/internal/evaluation" | ||
"github.com/Samasource/jen/src/internal/exec" | ||
logging "github.com/Samasource/jen/src/internal/logging" | ||
) | ||
|
||
// Confirm represents a conditional step that executes its child executable only if | ||
// user answers Yes when prompted for given message | ||
type Confirm struct { | ||
Message string | ||
Then exec.Executables | ||
} | ||
|
||
func (c Confirm) String() string { | ||
return "confirm" | ||
} | ||
|
||
// Execute executes a child action only if user answers Yes when prompted for given message | ||
func (c Confirm) Execute(context exec.Context) error { | ||
message, err := evaluation.EvalTemplate(context, c.Message) | ||
if err != nil { | ||
return err | ||
} | ||
prompt := &survey.Confirm{ | ||
Message: message, | ||
Default: false, | ||
} | ||
value := false | ||
if err := survey.AskOne(prompt, &value); err != nil { | ||
return err | ||
} | ||
if !value { | ||
logging.Log("Skipping sub-steps because user cancelled") | ||
return nil | ||
} | ||
logging.Log("Executing sub-steps because user confirmed") | ||
return c.Then.Execute(context) | ||
} |
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