Class: Cyclid::Cli::User

Inherits:
Thor
  • Object
show all
Defined in:
lib/cyclid/cli/user.rb

Overview

‘user’ sub-command

Instance Method Summary collapse

Instance Method Details

#modifyObject



56
57
58
59
60
61
62
63
# File 'lib/cyclid/cli/user.rb', line 56

def modify
  client.user_modify(client.config.username,
                     email: options[:email],
                     password: options[:password],
                     secret: options[:secret])
rescue StandardError => ex
  abort "Failed to modify user: #{ex}"
end

#passwdObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cyclid/cli/user.rb', line 66

def passwd
  # Get the new password
  print 'Password: '
  password = STDIN.noecho(&:gets).chomp
  print "\nConfirm password: "
  confirm = STDIN.noecho(&:gets).chomp
  print "\n"
  abort 'Passwords do not match' unless password == confirm

  # Modify the user with the new password
  begin
    client.user_modify(client.config.username, password: password)
  rescue StandardError => ex
    abort "Failed to modify user: #{ex}"
  end
end

#showObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cyclid/cli/user.rb', line 23

def show
  user = client.user_get(client.config.username)

  # Pretty print the user details
  puts 'Username: '.colorize(:cyan) + user['username']
  puts 'Name: '.colorize(:cyan) + (user['name'] || '')
  puts 'Email: '.colorize(:cyan) + user['email']
  puts 'Organizations'.colorize(:cyan)
  if user['organizations'].any?
    user['organizations'].each do |org|
      puts "\t#{org}"
    end
  else
    puts "\tNone"
  end
rescue StandardError => ex
  abort "Failed to get user: #{ex}"
end