#! /usr/bin/ruby require 'sod' require_relative '../lib/tonton_web/auth' require 'io/console' class CreateTable < Sod::Action on "--create-table" def call(*) context.tauth.create_tables end end class CreateUser < Sod::Command handle "create-user" class Username < Sod::Action on "--username", argument: "USERNAME" def call(username) = context.input[:username] = username end class Name < Sod::Action on "--name", argument: "NAME" def call(name) = context.input[:name] = name end class Email < Sod::Action on "--email", argument: "EMAIL" def call(email) = context.input[:email] = email end on Username on Name on Email def call context.input[:password] = IO::console.getpass("User password: ") context.tauth.create_user(**context.input) end end class DeleteUser < Sod::Action on "--delete-user", argument: "USER_ID" def call(user_id) context.tauth.delete_user user_id end end class Info < Sod::Command handle "info" description "Information about user." class Username < Sod::Action on "--username", argument: "TEXT" def call text puts context.tauth.find_user(username: text) end end on Username end tauth = TonTonWeb::Auth.new Dir.getwd context = Sod::Context[tauth: tauth, input: {}] cli = Sod.new(banner: "Tauth 0.0.0: TonTon Auth") do on(CreateTable, context:) on(CreateUser, context:) on(DeleteUser, context:) on(Info, context:) on Sod::Prefabs::Actions::Help, self end cli.call