Commit 629c3d1e authored by Addshore's avatar Addshore 🏄
Browse files

Add no-interaction option to prompt flows

parent 18545f5c
......@@ -36,6 +36,7 @@ var mwddCmd = &cobra.Command{
mwdd := mwdd.DefaultForUser()
mwdd.EnsureReady()
if mwdd.Env().Missing("PORT") {
if !NoInteraction {
prompt := promptui.Prompt{
Label: "What port would you like to use for your development environment?",
Default: ports.FreeUpFrom("8080"),
......@@ -48,6 +49,9 @@ var mwddCmd = &cobra.Command{
fmt.Println("Can't continue without a port")
os.Exit(1)
}
} else {
mwdd.Env().Set("PORT", ports.FreeUpFrom("8080"))
}
}
},
}
......@@ -96,6 +100,7 @@ var mwddResumeCmd = &cobra.Command{
func init() {
mwddCmd.PersistentFlags().IntVarP(&Verbosity, "verbosity", "v", 1, "verbosity level (1-2)")
mwddCmd.PersistentFlags().BoolVarP(&NoInteraction, "no-interaction", "n", false, "Do not ask any interactive question")
mwddCmd.AddCommand(mwddWhereCmd)
mwddCmd.AddCommand(mwddDestroyCmd)
......
......@@ -49,6 +49,7 @@ var mwddMediawikiCmd = &cobra.Command{
usrDir := usr.HomeDir
if mwdd.Env().Missing("MEDIAWIKI_VOLUMES_CODE") {
if !NoInteraction {
// Prompt the user for a directory or confirmation
dirPrompt := promptui.Prompt{
Label: "What directory would you like to store MediaWiki source code in?",
......@@ -62,7 +63,9 @@ var mwddMediawikiCmd = &cobra.Command{
fmt.Println("Can't continue without a MediaWiki code directory")
os.Exit(1)
}
} else {
mwdd.Env().Set("MEDIAWIKI_VOLUMES_CODE", mediawiki.GuessMediaWikiDirectoryBasedOnContext())
}
}
// Default the mediawiki container to a .composer directory in the running users home dir
......@@ -85,22 +88,31 @@ var mwddMediawikiCmd = &cobra.Command{
// TODO ask if they want to get any more skins and extensions?
// TODO async cloning of repos for speed!
if !mediawiki.MediaWikiIsPresent() {
if !NoInteraction {
cloneMwPrompt := promptui.Prompt{
Label: "MediaWiki code not detected in " + mwdd.Env().Get("MEDIAWIKI_VOLUMES_CODE") + ". Do you want to clone it now?",
IsConfirm: true,
}
_, err := cloneMwPrompt.Run()
setupOpts.GetMediaWiki = err == nil
} else {
setupOpts.GetMediaWiki = true
}
}
if !mediawiki.VectorIsPresent() {
if !NoInteraction {
cloneMwPrompt := promptui.Prompt{
Label: "Vector skin is not detected in " + mwdd.Env().Get("MEDIAWIKI_VOLUMES_CODE") + ". Do you want to clone it from Gerrit?",
IsConfirm: true,
}
_, err := cloneMwPrompt.Run()
setupOpts.GetVector = err == nil
} else {
setupOpts.GetVector = true
}
}
if setupOpts.GetMediaWiki || setupOpts.GetVector {
if !NoInteraction {
cloneFromGithubPrompt := promptui.Prompt{
Label: "Do you want to clone from Github for extra speed? (your git remotes will be switched to Gerrit after download)",
IsConfirm: true,
......@@ -136,7 +148,12 @@ var mwddMediawikiCmd = &cobra.Command{
}
setupOpts.GerritUsername = gerritUsername
}
setupOpts.UseShallow = err == nil
} else {
setupOpts.UseGithub = true
setupOpts.UseShallow = true
// Default is ssh, but http is the only non interactive choice we can make here..
setupOpts.GerritInteractionType = "http"
}
}
if setupOpts.GetMediaWiki || setupOpts.GetVector {
......
......@@ -29,8 +29,8 @@ import (
// Verbosity indicating verbose mode.
var Verbosity int
// NonInteractive skips prompts with a yes
var NonInteractive bool
// NoInteraction skips prompts with a yes or default values
var NoInteraction bool
// These vars are currently used by the docker exec command
......
......@@ -38,19 +38,23 @@ var updateCmd = &cobra.Command{
fmt.Println("New update found: " + toUpdateToOrMessage)
if !NoInteraction {
updatePrompt := promptui.Prompt{
Label: " Do you want to update?",
IsConfirm: true,
}
_, err := updatePrompt.Run()
if err == nil {
// Note: technically there is a small race condition here, and we might update to a newer version if it was release between stages
if err != nil {
return
}
}
// Technically there is a small race condition here, and we might update to a newer version if it was release between stages
updateSuccess, updateMessage := updater.Update(Version, GitSummary, Verbosity >= 2)
fmt.Println(updateMessage)
if !updateSuccess {
os.Exit(1)
}
}
},
}
......@@ -58,4 +62,5 @@ func init() {
rootCmd.AddCommand(updateCmd)
updateCmd.PersistentFlags().IntVarP(&Verbosity, "verbosity", "v", 1, "verbosity level (1-2)")
updateCmd.PersistentFlags().BoolVarP(&NoInteraction, "no-interaction", "n", false, "Do not ask any interactive question")
}
......@@ -13,6 +13,9 @@ trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT
# Run this integration test using a non standard port
./bin/mw docker env set PORT 9191
# And already fill in the location of mediawiki
./bin/mw docker env set MEDIAWIKI_VOLUMES_CODE $(pwd)/mediawiki
# So we should get no prompts, even though we don't pass --no-interaction
# Create
./bin/mw docker mediawiki create
......
......@@ -9,10 +9,13 @@ trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT
# Setup the default hosts in hosts file
./bin/mw docker hosts add
# --no-interaction, as the first time we run a docker command it'll prompt us for the port, default selected is 8080
./bin/mw docker hosts add --no-interaction
# Create
./bin/mw docker mediawiki create
# Create, from the mediawiki dir, to allow --no-interaction to detect the existing mediawiki directory, setting the volume path
cd ./mediawiki
./../bin/mw docker mediawiki create --no-interaction
cd ./..
# Create: Validate the basic stuff
./bin/mw docker docker-compose ps
......
......@@ -8,6 +8,10 @@ trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# echo an error message before exiting
trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT
# Set some corret values so we don't get asked
./bin/mw docker env set PORT 8080
./bin/mw docker env set MEDIAWIKI_VOLUMES_CODE $(pwd)/mediawiki
# Setup the default hosts in hosts file
./bin/mw docker hosts add
......
......@@ -10,13 +10,6 @@ docker-compose version
# Output CLI version
./bin/mw version
# Setup things that otherwise need user input
./bin/mw docker env set PORT 8080
./bin/mw docker env set MEDIAWIKI_VOLUMES_CODE $(pwd)/mediawiki
# And output their values
./bin/mw docker env list
cat $(./bin/mw docker env where)
# Create a fresh LocalSettings.php file
rm -f mediawiki/LocalSettings.php
echo "<?php" >> mediawiki/LocalSettings.php
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment