Updated cli
This commit is contained in:
parent
fc0babff13
commit
60a714fa82
5 changed files with 102 additions and 103 deletions
|
@ -28,8 +28,9 @@ COPY ./scripts ./scripts
|
||||||
RUN . ./scripts/build.sh ${BUILD_ENV}
|
RUN . ./scripts/build.sh ${BUILD_ENV}
|
||||||
|
|
||||||
FROM scratch as runner
|
FROM scratch as runner
|
||||||
COPY --from=micrate-builder /app/bin/micrate .
|
WORKDIR /
|
||||||
COPY --from=builder /app/bin/mw .
|
COPY --from=micrate-builder /app/bin/micrate ./bin/micrate
|
||||||
|
COPY --from=builder /app/bin/mw ./bin/mw
|
||||||
COPY ./db ./db
|
COPY ./db ./db
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
CMD [ "/mw" ]
|
CMD [ "mw" ]
|
||||||
|
|
|
@ -6,7 +6,7 @@ authors:
|
||||||
|
|
||||||
targets:
|
targets:
|
||||||
mw:
|
mw:
|
||||||
main: src/app.cr
|
main: src/mw.cr
|
||||||
|
|
||||||
crystal: 1.3.0
|
crystal: 1.3.0
|
||||||
|
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
require "commander"
|
|
||||||
require "./mw.cr"
|
|
||||||
|
|
||||||
def input(prompt : String) : String
|
|
||||||
print prompt
|
|
||||||
(gets || "").chomp.strip
|
|
||||||
end
|
|
||||||
|
|
||||||
cli = Commander::Command.new do |cmd|
|
|
||||||
cmd.use = "mw"
|
|
||||||
cmd.long = "Mentorenwahl"
|
|
||||||
|
|
||||||
cmd.run do
|
|
||||||
MW.run
|
|
||||||
end
|
|
||||||
|
|
||||||
cmd.commands.add do |c|
|
|
||||||
c.use = "version"
|
|
||||||
c.long = "Prints the current version"
|
|
||||||
|
|
||||||
c.run do
|
|
||||||
puts MW::VERSION
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
cmd.commands.add do |c|
|
|
||||||
c.use = "authors"
|
|
||||||
c.long = "Prints the authors"
|
|
||||||
|
|
||||||
c.run do
|
|
||||||
puts MW::AUTHORS.join(",\n")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
cmd.commands.add do |c|
|
|
||||||
c.use = "licenses"
|
|
||||||
c.long = "Prints the licenses of libraries used"
|
|
||||||
|
|
||||||
c.run do
|
|
||||||
puts MW::LICENSES
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
cmd.commands.add do |c|
|
|
||||||
c.use = "seed"
|
|
||||||
c.long = "Seeds the database with required data"
|
|
||||||
|
|
||||||
c.run do
|
|
||||||
puts "Seeding database with admin user..."
|
|
||||||
# firstname = input "Firstname: "
|
|
||||||
# lastname = input "Lastname: "
|
|
||||||
# email = input "Email: "
|
|
||||||
# password = input "Password: "
|
|
||||||
# password_confirmation = input "Password confirmation: "
|
|
||||||
data = {
|
|
||||||
"firstname" => input("Firstname: "),
|
|
||||||
"lastname" => input("Lastname: "),
|
|
||||||
"email" => input("Email: "),
|
|
||||||
"password" => MW::Auth.hash_password(input("Password: ")),
|
|
||||||
"role" => MW::Db::UserRole::Admin.to_s,
|
|
||||||
}
|
|
||||||
password_confirmation = input("Password confirmation: ")
|
|
||||||
|
|
||||||
if data.values.any?(&.empty?)
|
|
||||||
abort "Values can't be empty!"
|
|
||||||
elsif !MW::Auth.verify_password?(password_confirmation, data["password"])
|
|
||||||
abort "Passwords do not match!"
|
|
||||||
end
|
|
||||||
|
|
||||||
puts "---"
|
|
||||||
data.each { |k, v| puts "#{k.capitalize}: #{v}" }
|
|
||||||
puts "---"
|
|
||||||
|
|
||||||
unless input("Are you sure? (y/n) ") == "y"
|
|
||||||
abort "Aborted!"
|
|
||||||
end
|
|
||||||
|
|
||||||
puts "Seeding database with admin user..."
|
|
||||||
|
|
||||||
user = MW::Db::User.create!(data)
|
|
||||||
admin = MW::Db::Admin.create!(user_id: user.id)
|
|
||||||
|
|
||||||
puts "Done!"
|
|
||||||
|
|
||||||
puts "---"
|
|
||||||
puts "User id: #{user.id}"
|
|
||||||
puts "Admin id: #{admin.id}"
|
|
||||||
puts "Token: #{MW::Auth.create_user_jwt(user_id: user.id.not_nil!)}"
|
|
||||||
puts "---"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Commander.run(cli, ARGV)
|
|
97
docker/backend/src/mw/cli.cr
Normal file
97
docker/backend/src/mw/cli.cr
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
require "commander"
|
||||||
|
require "compiled_license"
|
||||||
|
|
||||||
|
require "./db"
|
||||||
|
|
||||||
|
module MW
|
||||||
|
module Cli
|
||||||
|
extend self
|
||||||
|
|
||||||
|
private def input(prompt : String) : String
|
||||||
|
print prompt
|
||||||
|
(gets || "").chomp.strip
|
||||||
|
end
|
||||||
|
|
||||||
|
cli = Commander::Command.new do |cmd|
|
||||||
|
cmd.use = "mw"
|
||||||
|
cmd.long = "Mentorenwahl"
|
||||||
|
|
||||||
|
cmd.run do
|
||||||
|
MW.run
|
||||||
|
end
|
||||||
|
|
||||||
|
cmd.commands.add do |c|
|
||||||
|
c.use = "version"
|
||||||
|
c.long = "Prints the current version"
|
||||||
|
|
||||||
|
c.run do
|
||||||
|
puts MW::VERSION
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
cmd.commands.add do |c|
|
||||||
|
c.use = "authors"
|
||||||
|
c.long = "Prints the authors"
|
||||||
|
|
||||||
|
c.run do
|
||||||
|
puts MW::AUTHORS.join(",\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
cmd.commands.add do |c|
|
||||||
|
c.use = "licenses"
|
||||||
|
c.long = "Prints the licenses of libraries used"
|
||||||
|
|
||||||
|
c.run do
|
||||||
|
puts CompiledLicense::LICENSES
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
cmd.commands.add do |c|
|
||||||
|
c.use = "seed"
|
||||||
|
c.long = "Seeds the database with required data"
|
||||||
|
|
||||||
|
c.run do
|
||||||
|
puts "Seeding database with admin user..."
|
||||||
|
data = {
|
||||||
|
"firstname" => input("Firstname: "),
|
||||||
|
"lastname" => input("Lastname: "),
|
||||||
|
"email" => input("Email: "),
|
||||||
|
"password" => Auth.hash_password(input("Password: ")),
|
||||||
|
"role" => Db::UserRole::Admin.to_s,
|
||||||
|
}
|
||||||
|
password_confirmation = input("Password confirmation: ")
|
||||||
|
|
||||||
|
if data.values.any?(&.empty?)
|
||||||
|
abort "Values can't be empty!"
|
||||||
|
elsif !Auth.verify_password?(password_confirmation, data["password"])
|
||||||
|
abort "Passwords do not match!"
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "---"
|
||||||
|
data.each { |k, v| puts "#{k.capitalize}: #{v}" }
|
||||||
|
puts "---"
|
||||||
|
|
||||||
|
unless input("Are you sure? (y/N) ").downcase == "y"
|
||||||
|
abort "Aborted!"
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Seeding database with admin user..."
|
||||||
|
|
||||||
|
user = Db::User.create!(data)
|
||||||
|
admin = Db::Admin.create!(user_id: user.id)
|
||||||
|
|
||||||
|
puts "Done!"
|
||||||
|
|
||||||
|
puts "---"
|
||||||
|
puts "User id: #{user.id}"
|
||||||
|
puts "Admin id: #{admin.id}"
|
||||||
|
puts "Token: #{Auth.create_user_jwt(user_id: user.id.not_nil!)}"
|
||||||
|
puts "---"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Commander.run(cli, ARGV)
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +0,0 @@
|
||||||
require "compiled_license"
|
|
||||||
|
|
||||||
module MW
|
|
||||||
LICENSES = CompiledLicense::LICENSES
|
|
||||||
end
|
|
Loading…
Reference in a new issue