1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#!/usr/bin/env ruby
require 'yaml'
core_order = [ "username",
"fullname",
"email",
"groups",
"pgp_keyid",
"pgp_revoked_keyids",
"ssh_keys",
"extra" ]
extra_order = [ "alias",
"other_contact",
"roles",
"website",
"occupation",
"yob",
"location",
"languages",
"interests",
"favorite_distros" ]
_core_order = Hash[[*core_order.map.with_index]]
_extra_order = Hash[[*extra_order.map.with_index]]
print YAML::load(STDIN)
.sort_by{|u| u["username"]}
.map{|u| Hash[u.sort_by{|k,v| _core_order[k]}]}
.each{|u|u["extra"] = Hash[u["extra"].sort_by{|k,v| _extra_order[k]}] if u["extra"]}
.to_yaml
|