Doug just posted an ode to the Linux command line over at the Plain Black staff blog.
I've been getting a lot of joy out of the command line today too thanks to Graham's ridiculously useful WGDev. One wgd command that I only started using in earnest today is the ls command. In its most basic form, it lets you print out a list of assets on your site:
$ wgd ls /home getting_started your_next_step the_latest_news tell_a_friend documentation site_map
I added a bunch of extensions to ls today, the first one being a -r option that tells ls to recursively list assets. Given that this prints to STDOUT, you can pipe this into any other command line tool to manipulate the output. For example, to list all assets that have the word "you" in their menu title:
$ wgd ls /root -f "%menuTitle%" -r | grep -i you Profile Account Layout Inbox Account Layout Friends Layout Template Account Layout Shop Account Layout Contributions Layout Default Account Layout Layout Your Next Step
(the -f "%menuTitle%" option above tells the command to output only the menuTitle property of each asset).
Under the hood ls is calling asset->getLineage(), so I exposed a few of the getLineage API options to ls.
For example, this is one way of getting a sorted list of Survey templates on your site:
$ wgd ls root -r --includeOnlyClass WebGUI::Asset::Template -f "%url% %namespace%" | perl -ane 'print "$F[0] ($F[1])\n" if $F[1] =~ m/survey/i' | sort root/import/expireincompletesurveyresponses/expireincompletesurveyresponses (ExpireIncompleteSurveyResponses) root/import/survey/default-answer-edit (Survey/Edit) root/import/survey/default-feedback (Survey/Feedback) root/import/survey/default-gradebook-report (Survey/Gradebook) root/import/survey/default-overview-report (Survey/Overview) root/import/survey/default-question-edit (Survey/Edit) root/import/survey/default-questions (Survey/Take) root/import/survey/default-section-edit (Survey/Edit) root/import/survey/default-survey-edit (Survey/Edit) root/import/survey/default-survey-summary (Survey/Summary) root/import/survey/default-survey (Survey) root/import/survey/default-survey-take (Survey/Take) root/import/survey/default-test-results (Survey/TestResults)
While I was writing this post, Andy asked me to provide him with a list of all Carousel wobjects on a site we're working on. That's as easy as:
$ wgd ls -r root --includeOnlyClass WebGUI::Asset::Wobject::Carousel
The most useful option I added to ls is the ?filter smartmatch filter option. This option filters the results using an asset property of your choosing. Format looks like "%url% ~~ smartmatch", where "url" is the field to filter against, and "smartmatch" is either a Perl regular expression such as "/(?i:partial_match)/" or a string such as "my_exact_match".
For example, the following command lists all templates that include absolute urls. We generate the output to an html file so that someone can easily open all the links and manually review/remove the absolute urls:
$ wgd ls -r /root --filter "%template% ~~ /http:///" --includeOnlyClass WebGUI::Asset::Template --format "<a href=http://dev.localhost.localdomain/%url%?func=edit>%url%</a><br>" > links.html
links.html then contains:
<a href=http://dev.localhost.localdomain/style_01?func=edit>style_01</a><br> <a href=http://dev.localhost.localdomain/style_02?func=edit>style_02</a><br> <a href=http://dev.localhost.localdomain/style_03?func=edit>style_03</a><br> ...
One type of command that I can see myself using a lot in the future is the following, which displays all assets that are viewable to a specific group (in this case the "Turn Admin On" group, which has an id of "12″):
$ wgd ls -r root --format "%groupIdView% %url%" --filter "%groupIdView% ~~ 12" 12 root/import/newsletter 12 root/import/projectmanager/resource 12 root/import/wiki
Alternatively, you can use a variation of the above to list all assets that are NOT viewable to a certain group (or groups). This is great for finding assets that have accidentally been set to say, Admins, when you want them viewable by Registered Users. For example, the following command lists assets that are not viewable to the default "Visitors", "Everyone", or "Registered Users" groups:
$ wgd ls -r root --format "%groupIdView% %url%" | perl -ane 'print "$F[0] $F[1]\n" if !grep {$F[0] eq $_} qw(1 2 7)'
12 root/import/newsletter
12 root/import/projectmanager/resource
12 root/import/wiki
All of these commands take in the order of 1 second to run, which is a lot less time consuming than manually reviewing your site asset-by-asset. And if you incorporate them into your test suite, you can re-verify their output against your site policy/expectations whenever you like.














