Refactor copypasta to a private function in instance.ex
This commit is contained in:
parent
cbe22deb51
commit
d924b6cd3d
@ -59,49 +59,37 @@ def run(["new" | rest]) do
|
||||
|
||||
unless not proceed? do
|
||||
domain =
|
||||
Keyword.get(options, :domain) ||
|
||||
Mix.shell().prompt("What domain will your instance use? (e.g. pleroma.soykaf.com)")
|
||||
|> String.trim()
|
||||
get_option(
|
||||
options,
|
||||
:domain,
|
||||
"What domain will your instance use? (e.g pleroma.soykaf.com)"
|
||||
)
|
||||
|
||||
name =
|
||||
Keyword.get(options, :name) ||
|
||||
Mix.shell().prompt("What is the name of your instance? (e.g. Pleroma/Soykaf)")
|
||||
|> String.trim()
|
||||
get_option(options, :name, "What is the name of your instance? (e.g. Pleroma/Soykaf)")
|
||||
|
||||
email =
|
||||
Keyword.get(options, :admin_email) ||
|
||||
Mix.shell().prompt("What is your admin email address?")
|
||||
|> String.trim()
|
||||
email = get_option(options, :admin_email, "What is your admin email address?")
|
||||
|
||||
dbhost =
|
||||
Keyword.get(options, :dbhost) ||
|
||||
case Mix.shell().prompt("What is the hostname of your database? [localhost]") do
|
||||
"\n" -> "localhost"
|
||||
dbhost -> dbhost |> String.trim()
|
||||
end
|
||||
dbhost = get_option(options, :dbhost, "What is the hostname of your database?", "localhost")
|
||||
|
||||
dbname =
|
||||
Keyword.get(options, :dbname) ||
|
||||
case Mix.shell().prompt("What is the name of your database? [pleroma_dev]") do
|
||||
"\n" -> "pleroma_dev"
|
||||
dbname -> dbname |> String.trim()
|
||||
end
|
||||
dbname = get_option(options, :dbname, "What is the name of your database?", "pleroma_dev")
|
||||
|
||||
dbuser =
|
||||
Keyword.get(options, :dbuser) ||
|
||||
case Mix.shell().prompt("What is the user used to connect to your database? [pleroma]") do
|
||||
"\n" -> "pleroma"
|
||||
dbuser -> dbuser |> String.trim()
|
||||
end
|
||||
get_option(
|
||||
options,
|
||||
:dbuser,
|
||||
"What is the user used to connect to your database?",
|
||||
"pleroma"
|
||||
)
|
||||
|
||||
dbpass =
|
||||
Keyword.get(options, :dbpass) ||
|
||||
case Mix.shell().prompt(
|
||||
"What is the password used to connect to your database? [autogenerated]"
|
||||
) do
|
||||
"\n" -> :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64)
|
||||
dbpass -> dbpass |> String.trim()
|
||||
end
|
||||
get_option(
|
||||
options,
|
||||
:dbpass,
|
||||
"What is the password used to connect to your database?",
|
||||
:crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64),
|
||||
"autogenerated"
|
||||
)
|
||||
|
||||
secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64)
|
||||
|
||||
@ -160,4 +148,18 @@ def run(["new" | rest]) do
|
||||
defp escape_sh_path(path) do
|
||||
~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
|
||||
end
|
||||
|
||||
defp get_option(options, opt, prompt, def \\ nil, defname \\ nil) do
|
||||
Keyword.get(options, opt) ||
|
||||
case Mix.shell().prompt("#{prompt} [#{defname || def}]") do
|
||||
"\n" ->
|
||||
case def do
|
||||
nil -> get_option(options, opt, prompt, def)
|
||||
def -> def
|
||||
end
|
||||
|
||||
opt ->
|
||||
opt |> String.trim()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user