Class: GridCLI::SignupCommand

Inherits:
BaseCommand show all
Defined in:
lib/gridcli/commands/signup.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#cmd, #desc

Instance Method Summary collapse

Methods inherited from BaseCommand

#add_format_option, #add_option, #error, #log, #output_format, #parse_dates, #parse_opts, #pop_arg, #pprint

Constructor Details

#initializeSignupCommand

Returns a new instance of SignupCommand.



3
4
5
# File 'lib/gridcli/commands/signup.rb', line 3

def initialize
  super "signup", "Create an account on the grid"
end

Instance Method Details

#run(args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gridcli/commands/signup.rb', line 11

def run(args)
  # handle options
  usage if args.length == 0
  username = args.shift
  parse_opts args

  username = GridCLI.hooker.invoke :before_signup, username

  @config["username"] = username
  @config.save
  
  begin
    log "Trying to create new user with name '#{username}'"
    User.new(:username => username, :token => @config['token']).save
    puts "New user created.  You are now known as '#{username}'"
  rescue ActiveResource::ClientError
    puts "Sorry, username '#{username}' already exists or contains non-alphanumeric characters."
  end
end

#usageObject



7
8
9
# File 'lib/gridcli/commands/signup.rb', line 7

def usage
  super "<username>"
end