Sha256: 74e7cd4a189233d8b81beb744324c535a6ce58411835ba7a3f40a7945b705bbc

Contents?: true

Size: 1.68 KB

Versions: 7

Compression:

Stored size: 1.68 KB

Contents

require "vmc/cli/command"

module VMC
  class User < Command
    desc "create [EMAIL]", "Create a user"
    group :admin, :user, :hidden => true
    flag(:email) {
      ask("Email")
    }
    flag(:password) {
      ask("Password", :echo => "*", :forget => true)
    }
    flag(:verify) {
      ask("Verify Password", :echo => "*", :forget => true)
    }
    def create(email = nil)
      email ||= input(:email)
      password = input(:password)

      if !force? && password != input(:verify)
        fail "Passwords don't match."
      end

      with_progress("Creating user") do
        client.register(email, password)
      end
    end

    desc "delete [EMAIL]", "Delete a user"
    group :admin, :user, :hidden => true
    flag(:really) { |email|
      force? || ask("Really delete user #{c(email, :name)}?", :default => false)
    }
    def delete(email)
      return unless input(:really, email)

      with_progress("Deleting #{c(email, :name)}") do
        client.user(email).delete!
      end
    ensure
      forget(:really)
    end

    desc "passwd [EMAIL]", "Update a user's password"
    group :admin, :user, :hidden => true
    flag(:email) {
      ask("Email")
    }
    flag(:password) {
      ask("Password", :echo => "*", :forget => true)
    }
    flag(:verify) {
      ask("Verify Password", :echo => "*", :forget => true)
    }
    def passwd(email = nil)
      email ||= input(:email)
      password = input(:password)
      verify = input(:verify)

      if password != verify
        fail "Passwords don't match."
      end

      with_progress("Changing password") do
        user = client.user(email)
        user.password = password
        user.update!
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vmc-0.4.0.beta.12 vmc-ng/lib/vmc/cli/user.rb
vmc-0.4.0.beta.11 vmc-ng/lib/vmc/cli/user.rb
vmc-0.4.0.beta.10 vmc-ng/lib/vmc/cli/user.rb
vmc-0.4.0.beta.9 lib/vmc/cli/user.rb
vmc-0.4.0.beta.8 vmc-ng/lib/vmc/cli/user.rb
vmc-0.4.0.beta.7 vmc-ng/lib/vmc/cli/user.rb
vmc-0.4.0.beta.6 lib/vmc/cli/user.rb