Sha256: 0c3fcab356442ca044bf6c9d96e12ee19fbdef7f34a2fd93cb33e30353daaa45

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require 'thor'
require 'pp'

class ArisControl::Thor < Thor
  desc 'add/update username', 'Adds/Updates  an aris user.'
  method_option :email,    type: :string, required: true, desc: 'The users email address. Used for web login.'
  method_option :ssh_key,  type: :string, desc: 'The users ssh public key. Used for git access via ssh.'
  method_option :env_vars, type: :hash,   desc: 'The users app env vars. Env vars will be accessible inside the app via ENV[VAR-NAME].'
  def add(name)
    opts = Hash.new.tap do |h|
      h[:email]    = options[:email]
      h[:ssh_key]  = options[:ssh_key]  if options[:ssh_key]
      h[:env_vars] = options[:env_vars] if options[:env_vars]
    end
    bookkeeper.add(name: name, **opts)
    puts "Added/Updated user: #{name}, #{options}"
    puts "-----------------------------"
    print_current_aris_users
  end

  desc 'delete name', 'Deletes aris user'
  def delete(name)
    bookkeeper.delete(name)
    puts "Removed user: #{name}"
    puts "-----------------------------"
    print_current_aris_users
  end

  desc 'list', 'Lists current aris-users'
  def list
    print_current_aris_users
  end

  private

  def print_current_aris_users
    puts "Current aris user database"
    puts "-----------------------------"
    pp bookkeeper.list
  end

  def bookkeeper
    @bookkeeper ||= ArisControl::Bookkeeper.new
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aris-control-1.1.1 lib/aris-control/thor.rb