20
20
Show information about a user.`[1:]
22
22
var helpDetails = `
23
By default, the YAML format is used and the user name is the current user.
23
By default, the YAML format is used and the user name is the current
29
juju show-user --format json
30
juju show-user --format yaml
30
juju show-user --format json
31
juju show-user --format yaml
37
38
// UserInfoAPI defines the API methods that the info command uses.
38
39
type UserInfoAPI interface {
51
52
func (c *infoCommandBase) SetFlags(f *gnuflag.FlagSet) {
52
f.BoolVar(&c.exactTime, "exact-time", false, "use full timestamp precision")
53
f.BoolVar(&c.exactTime, "exact-time", false, "Use full timestamp for connection times")
55
56
func NewShowUserCommand() cmd.Command {
139
140
Username: info.Username,
140
141
DisplayName: info.DisplayName,
141
142
Disabled: info.Disabled,
142
LastConnection: LastConnection(info.LastConnection, now, c.exactTime),
143
LastConnection: common.LastConnection(info.LastConnection, now, c.exactTime),
145
146
outInfo.DateCreated = info.DateCreated.String()
147
outInfo.DateCreated = UserFriendlyDuration(info.DateCreated, now)
148
outInfo.DateCreated = common.UserFriendlyDuration(info.DateCreated, now)
150
151
output = append(output, outInfo)
156
// LastConnection turns the *time.Time returned from the API server
157
// into a user facing string with either exact time or a user friendly
158
// string based on the args.
159
func LastConnection(connectionTime *time.Time, now time.Time, exact bool) string {
160
if connectionTime == nil {
161
return "never connected"
164
return connectionTime.String()
166
return UserFriendlyDuration(*connectionTime, now)
169
// UserFriendlyDuration translates a time in the past into a user
170
// friendly string representation relative to the "now" time argument.
171
func UserFriendlyDuration(when, now time.Time) string {
172
since := now.Sub(when)
173
// if over 24 hours ago, just say the date.
174
if since.Hours() >= 24 {
175
return when.Format("2006-01-02")
177
if since.Hours() >= 1 {
179
if int(since.Hours()) == 1 {
182
return fmt.Sprintf("%d %s ago", int(since.Hours()), unit)
184
if since.Minutes() >= 1 {
186
if int(since.Minutes()) == 1 {
189
return fmt.Sprintf("%d %s ago", int(since.Minutes()), unit)
191
if since.Seconds() >= 2 {
192
return fmt.Sprintf("%d seconds ago", int(since.Seconds()))