Class: GridCLI::ProfileCommand
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
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/gridcli/commands/profile.rb', line 3
def initialize
super "profile", "Show profile information for other users or update own profile", { :update => false }
add_option("--github-user username", "Set your username on github") { |u|
@opts[:github_username] = u
@opts[:update] = true
}
add_option("--name fullname", "Set your full name") { |u|
@opts[:name] = u
@opts[:update] = true
}
add_option("--avatar file", "Set your avatar (a text file)") { |u|
@opts[:avatar] = u
@opts[:update] = true
}
add_format_option
end
|
Instance Method Details
#run(args) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/gridcli/commands/profile.rb', line 24
def run(args)
username = (args.length == 0 || args.first.start_with?('-')) ? @config['username'] : args.shift
parse_opts args
begin
log "Trying to find user with name '#{username}'"
user = User.find(username)
rescue ActiveResource::ResourceNotFound
puts "Sorry, username '#{username}' does not exist."
return
rescue ActiveResource::ClientError
puts "Sorry, you cannot see the profile for '#{username}'"
return
end
if @opts[:update]
[:github_username, :name].each { |n| user.send("#{n.to_s}=", @opts[n]) }
unless @opts[:avatar].nil?
if File.exists?(@opts[:avatar])
user.avatar = File.read(@opts[:avatar])
else
error("File #{@opts[:avatar]} does not exist")
end
end
user.id = username
user.save
end
pprint user.to_json
end
|
#usage ⇒ Object
20
21
22
|
# File 'lib/gridcli/commands/profile.rb', line 20
def usage
super "[username]"
end
|