#! /usr/bin/env ruby
# frozen_string_literal: true

require "securerandom"

ALLOWED_METHODS = %w[alphanumeric base64 hex random_bytes random_number uuid]

method, length = ARGV.first.split

abort "Invalid method: #{method}. Use: #{ALLOWED_METHODS}." unless ALLOWED_METHODS.include?(method)

computed_length = String(length).empty? ? ENV.fetch("minimum_length").to_i : length.to_i

print SecureRandom.public_send(method, computed_length)
