<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Feelings of White &#187; technical</title>
	<atom:link href="http://feelingsofwhite.com/category/technical/feed/" rel="self" type="application/rss+xml" />
	<link>http://feelingsofwhite.com</link>
	<description>this is where something witty goes</description>
	<lastBuildDate>Mon, 19 Jul 2010 21:27:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Inside the Secrets of The Behind the Making of The Music Revealed</title>
		<link>http://feelingsofwhite.com/2009/03/inside-the-secrets-of-the-behind-the-making-of-the-music-revealed/</link>
		<comments>http://feelingsofwhite.com/2009/03/inside-the-secrets-of-the-behind-the-making-of-the-music-revealed/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 06:05:52 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[funny]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[the void]]></category>
		<category><![CDATA[writing]]></category>
		<category><![CDATA[Battlestar Galactica]]></category>
		<category><![CDATA[plug]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.com/2009/03/inside-the-secrets-of-the-behind-the-making-of-the-music-revealed/</guid>
		<description><![CDATA[Join BSG Music computer Bear McCreary on this backstage tour of the Galactica where no one knows who the frak he is.  James Callis introduces us to the "Balter is the mutherfucking shit!!!" song and Edward James Olmos does some bear impressions. Rawr! Bonus: a special feature on The Ack Attack and her Lost Recaps!]]></description>
			<content:encoded><![CDATA[<p><span>
<p><a href="http://www.theackattack.net/?cat=24" target="_blank"><img style="float: right; margin: 0px 0px 0.5em 0.5em" height="261" alt="This article brought to you by: The Ack Attack! Putting the 'ack' in 'crack' since 2005" src="http://feelingsofwhite.com/wp-content/uploads/2009/03/broughttoyoubytheackattacklostreviews.png" width="289"></a>If <a href="http://theackattack.com" target="_blank">The Ack Attack<em>!</em></a> hadn’t already <a href="http://ack-attack.livejournal.com/537505.html" target="_blank">pointed out</a> today’s video, this post wouldn’t even <em>exist</em>. Contemplate that, <span style="letter-spacing: 0.1em; position: relative; top: 0.4em"><font face="Impact">my <span style="position: relative; top: -0.1em">un</span>dead friends.</font></span>
<p>I must advise you to <big><strong>peruse Ack’s <a href="http://www.theackattack.net/?cat=24" target="_blank">weekly Lost Recaps</a></strong></big>. And this isn’t the <a href="http://feelingsofwhite.com/2008/03/congratulations-universe/">first time</a> I’ve called attention to Ack’s fine fine work screen-capping &amp; and re-captioning the latest <em>Lost</em> episodes. Drenching them as she does in delicious hilariousness.</p>
<p><strong>I am <em>really</em> enjoying <em>Lost</em> this season</strong> — <nobreak><span style="vertical-align: middle">It’s </span><span style="letter-spacing: 0em"><span style="font-size: 100%">F</span><span style="font-size: 110%">r</span><span style="font-size: 120%">a</span><span style="font-size: 130%">k</span><span style="font-size: 140%">i</span><span style="font-size: 150%">n</span><span style="font-size: 160%">g </span><span style="font-size: 170%">D</span><span style="font-size: 180%">h</span><span style="font-size: 170%">a</span><span style="font-size: 160%">r</span><span style="font-size: 150%">m</span><span style="font-size: 140%">a</span><span style="font-size: 130%">r</span><span style="font-size: 120%">f</span><span style="font-size: 110%">i</span><span style="font-size: 100%">c</span></span></span></nobreak>. After getting my weekly hit of mind-blowing island hijinks, the <a href="http://www.theackattack.net/?cat=24" target="_blank">Lost Recaps</a> are what I look forward to. <small>(and they seem to be finished by the following Sunday)</small></p>
<table style="clear: both; margin: 1em" width="500" align="center">
<tbody>
<tr>
<td>
<hr style="border-right: black 2px solid; border-top: black 2px solid; border-left: black 2px solid; border-bottom: black 2px solid"> </td>
<td style="width: 15em" align="middle"><em><small>…on with the show…</small></em></td>
<td>
<hr style="border-right: black 2px solid; border-top: black 2px solid; border-left: black 2px solid; border-bottom: black 2px solid"> </td>
</tr>
</tbody>
</table>
<p style="clear: both"><img style="clear: both; border-right: black 4px solid; border-top: black 4px solid; float: left; margin: 0px 1em 0.5em 0px; border-left: black 4px solid; border-bottom: black 4px solid" height="133" alt="Inside the Secrets of the Behind the making of the Music of Battlestar Galactica Revealed" src="http://feelingsofwhite.com/wp-content/uploads/2009/03/inside-the-secrets-of-the-behind-the-make-of-the-music-of-battlestar-galactica-bsg-revealed.png" width="240">Follow Galactica composer Bear McCreary as he exposes the seedy underbelly of BSG’s music making process.&nbsp; The running gag is that no one knows who the hell he is and he spends most of his time <span style="font-size: 75%; color: green; position: relative; top: -0.2em">$</span><span style="font-size: 75%; color: green; position: relative; top: 0.1em">$</span>paying<span style="font-size: 75%; color: green; position: relative; top: -0.2em">$</span><span style="font-size: 75%; color: green; position: relative; top: 0.1em">$</span> people to call him a creative genius and trying to get himself invited to the wrap party. </p>
<p><small style="font-variant: small-caps">Highlights Include:</small> Edward James Olmos mimicking a circus bear and James Callis forcing a reluctant McCreary to compose his <em><big><sub>♫</sub><sup>Baltar is the </sup><sub>Motherfucking Shit</sub><big>!!</big><sup>♫</sup></big></em> opus which he insists Ron Moore already loves and listens to every morning before jogging. It’s little to do with the music and more an excuse to hear things like Katee Sachoff bemoan <font style="position: relative; top: 0.1em" face="monospace">this isn’t fair, <span style="position: relative; top: 0.1em">none of us even know who the fuck this guy is</span></font> and features an impressive number of familiar and behind the screen BSG talent.</p>
<p> <center>
<div class="legioncenter" style="padding-right: 5px; padding-left: 5px; padding-bottom: 6px; margin: 0.5em 1em; width: 480px; color: white; padding-top: 6px; background-color: black"><!--<big><b>Inside the Secrets of the Behind the making of the Music of Battlestar Galactica Revealed</b></big> </p>
<p>--><small>Part 1 [length 9:21]</small> <br /><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/fxzvIlVnCPA&amp;hl=en&amp;fs=1&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/fxzvIlVnCPA&amp;hl=en&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></div>
<p></center> <center></center><span id="more-472"></span></span> <center>
<div class="legioncenter" style="padding-right: 5px; padding-left: 5px; padding-bottom: 6px; margin: 0.5em 1em; width: 480px; color: white; padding-top: 6px; background-color: black"><small>Part 2 [length 8:58]</small><br /><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/cTRVs1qYXc8&amp;hl=en&amp;fs=1&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/cTRVs1qYXc8&amp;hl=en&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></div>
<p></center> <center>
<div class="legioncenter" style="padding-right: 5px; padding-left: 5px; padding-bottom: 6px; margin: 0.5em 1em; width: 480px; color: white; padding-top: 6px; background-color: black"><small>Part 3 [length 4:13]</small> <br /><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/OlxGyLzeBng&amp;hl=en&amp;fs=1&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/OlxGyLzeBng&amp;hl=en&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></div>
<p></center></p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2009/03/inside-the-secrets-of-the-behind-the-making-of-the-music-revealed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jimbo vs. The Tooltip</title>
		<link>http://feelingsofwhite.com/2008/12/tooltips/</link>
		<comments>http://feelingsofwhite.com/2008/12/tooltips/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 07:07:57 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[technical]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://FeelingsOfWhite.com/2008/12/tooltips/</guid>
		<description><![CDATA[In this installment, we learn how all classes should be designed around how the tooltips appear to other developers.  Well, not quite.  Not food for thought, more a refreshing light snack.]]></description>
			<content:encoded><![CDATA[<table style="border-right: black 0px solid; border-top: black 0px solid; border-left: black 0px solid; border-bottom: black 0px solid" cellspacing="4" cellpadding="0">
<tbody>
<tr>
<td align="center" colspan="3"><big><strong>Here Are Your Choices! </strong></big></td>
</tr>
<tr>
<td><center><big>The Flattened Defender</big></center><img title="public interface IAppleStrategy { }&#13;&#10;&#13;&#10;public class Apple&#13;&#10;{&#13;&#10;&#13;&#10;    public class Tasty : IAppleStrategy { }&#13;&#10;&#13;&#10;    public class UnRipened : IAppleStrategy { }&#13;&#10;&#13;&#10;    public class Rotten : IAppleStrategy { }&#13;&#10;}" style="border-right: black 2px solid; border-top: black 2px solid; border-left: black 2px solid; border-bottom: black 2px solid" height="240" alt="public interface IAppleStrategy { }&#13;&#10;&#13;&#10;public class Apple&#13;&#10;{&#13;&#10;&#13;&#10;    public class Tasty : IAppleStrategy { }&#13;&#10;&#13;&#10;    public class UnRipened : IAppleStrategy { }&#13;&#10;&#13;&#10;    public class Rotten : IAppleStrategy { }&#13;&#10;}" src="http://feelingsofwhite.com/wp-content/uploads/2008/12/vs-nonnested2.png" width="250" /> </td>
<td><img title="Vs" style="display: inline" height="240" alt="Vs" src="http://feelingsofwhite.com/wp-content/uploads/2008/12/vstransparent2.gif" width="40" border="0" />&#160;</td>
<td><center><big>The Nested Challenger</big></center><img title="public class Apple&#13;&#10;{&#13;&#10;    public interface IStragegy { }&#13;&#10;    &#13;&#10;&#13;&#10;    public class Tasty : IStragegy { }&#13;&#10;&#13;&#10;    public class UnRipened : IStragegy { }&#13;&#10;&#13;&#10;    public class Rotten : IStragegy { }&#13;&#10;}" style="border-right: black 2px solid; border-top: black 2px solid; border-left: black 2px solid; border-bottom: black 2px solid" height="240" alt="public class Apple&#13;&#10;{&#13;&#10;    public interface IStragegy { }&#13;&#10;    &#13;&#10;&#13;&#10;    public class Tasty : IStragegy { }&#13;&#10;&#13;&#10;    public class UnRipened : IStragegy { }&#13;&#10;&#13;&#10;    public class Rotten : IStragegy { }&#13;&#10;}" src="http://feelingsofwhite.com/wp-content/uploads/2008/12/vs-nested2.png" width="250" border="0" /> </td>
</tr>
</tbody>
</table>
<p>Perhaps you already have a strong preference just from looking at them; that's fine. Instead of debating and declaring one a winner, lets examine <em>how</em> I arrived at my own decision, when I was recently faced with this question. </p>
<p> <span id="more-269"></span>
<div class="legionpic legionside" style="padding-right: 4px; padding-left: 4px; float: right; padding-bottom: 5px; margin: 0px 0px 0.5em 1em; width: 254px; color: white; padding-top: 5px; background-color: black; text-align: center"><img height="128" src="http://feelingsofwhite.com/wp-content/uploads/2008/12/dropdown.png" width="246" xstyle="xborder: 2px solid black;" />     <br /><small>Nested classes + intellisense      <br />= easier for developers</small> </div>
<p>I was considering refactoring to the nested class scenario. I've grown somewhat fond of nested classes for their ability to group things together and for the way intellisense can provide targeted hints with its dropdown suggestions. Instead of trying to hunt down a <font face="monospace">TastyAppleStrategy</font> or <font face="monospace">UnripenedAppleStrategy</font> and wonder what else may exist, you can just type &quot;<font face="monospace">Apple.</font>&quot; and see all available choices. without ever hitting comments or navigating code. Its all right there for the developer stuck trying use my convoluted code. O 'course, get too nested and you've just got a rats nest.</p>
<p>It doesn't matter how brilliant or easy my code is, because my target audience <small>(another developer)</small> didn't write the code himself. And <strong>your code, regardless its nature, is always regarded as unintelligible goobledygook</strong> by other developers. As a general rule, being forced to understand it has pissed them off as well. They want to deal as little as possible with your code, so they can go back to writing their own. Everyone understands their own code, they've spend their whole life writing their own code; it makes sense. Even if you disagree on the merits of nested classes, let's assume for what follows next that they are roughly of equal merit. The main usage point was this function: </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <img style="border-right: black 2px solid; border-top: black 2px solid; border-left: black 2px solid; border-bottom: black 2px solid" height="85" src="http://feelingsofwhite.com/wp-content/uploads/2008/12/tooltip-nested-fantasy-text.png" width="475" /></p>
<p>But what really happened with nested classes was less friendly tooltips:</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <img style="border-right: black 2px solid; border-top: black 2px solid; border-left: black 2px solid; border-bottom: black 2px solid" height="85" src="http://feelingsofwhite.com/wp-content/uploads/2008/12/tooltip-nested-real-text.png" width="475" /></p>
<p>Oh jeez, my meticulously constructed fantasy world crumbles around me. What if I abandon the refactor and stick with a flattened structure:</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <img style="border-right: black 2px solid; border-top: black 2px solid; border-left: black 2px solid; border-bottom: black 2px solid" height="85" src="http://feelingsofwhite.com/wp-content/uploads/2008/12/tooltip-flattened-real-text.png" width="475" /></p>
<p>A flattened structure yields the most helpful tooltips. Since invoking <font face="monospace">DoSomething</font> is the main use-case for developers-who-aren't-Me, I chose the one that's better documented by the IDE. </p>
<p>So, that's how I arrived at my choice. Seriously: The tooltip. Not like I planned out success criteria and did a focus group. More like 90% into the change to my obviously brilliant nested classes I noticed the tooltip, went &quot;Aw Fuck!&quot; and reverted the changes. The tooltip rules all! </p>
<p>There are a few points I'm attempting to make. One is to consider your target audience: other developers. Lazy, couldn't be bothered, highly overworked, incompetent, brilliant, will not read any specs, enjoy puzzling things out, developers. Naming and structuring your code is the biggest documentation you are likely to perform in any given project and there's a lot of potential things to guide your decision. </p>
<p>Much is written elsewhere involving the pursuit of technical excellence. Ways to code that in and of themselves that are beautiful monstrosities with no regard to the environment they inhabit. The best solutions integrate with the ecosystem of developer tools. &quot;The Best Way To Code&quot; stopped being an isolated academic question sometime around when our variables got colour-coded. The right(est) answer depends on your coding environment, Visual Studio version, your team-members, their prior experience and skill levels, what code-generators you're using -- you gotta consider it all. Which is ultimately impossible. If you want definite answers, go believe in creationism. </p>
<p>You could do worse than consider tooltips in your next design. And when Visual Studio changes their tool-tips <abbr text="I&#39;m on Visual Studio 2005 as I write this">next version</a>, you betcha: Its time to refactor that code. The Game just changed and everything I said is antiquated. </p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2008/12/tooltips/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Command Line Parsing using Attribute Decoration in .NET</title>
		<link>http://feelingsofwhite.com/2008/07/command-line-parsing/</link>
		<comments>http://feelingsofwhite.com/2008/07/command-line-parsing/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 06:48:08 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[technical]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://FeelingsOfWhite.com/?p=173</guid>
		<description><![CDATA[At some point, you'll have to write an application accepting command line arguments.  Typically a console application, but GUI apps can accept command lines too.  Its features and options will grow and you will become frustrated with .Net's default abilities.  You'll desire a robust parsing ability, and you'll wish to configure it easily, automatically and in an extensible way. Welcome to today's topic]]></description>
			<content:encoded><![CDATA[<h3 style="font-weight: bold; font-size: 180%; width: 20em">The Tease</h3>
<p>At some point, you'll have to write an application accepting command line arguments.&nbsp; Typically a console application, but GUI apps can accept command lines too.&nbsp; Its features and options will grow and you <i>will</i> become frustrated with .Net's default abilities.&nbsp; You'll desire a robust parsing ability, and you'll wish to configure it easily, automatically and in an extensible way.&nbsp; Welcome to today's topic</p>
<p>&nbsp;&nbsp;&nbsp; <img height="146" alt="screenshot of command-line program, demonstrating different usage patterns supported by the framework, described later in the document" src="http://feelingsofwhite.com/wp-content/uploads/2008/07/teasecmdprompt1.png" width="589" border="0"></p>
<p>Big whup, eh?&nbsp; But <b>let's see how simple it was to create</b>: just decorate a class' properties with attributes to describe the mapping.</p>
<div style="border-right: black 2px solid; border-top: black 2px solid; margin-left: 5px; overflow: scroll; border-left: black 2px solid; width: 600px; border-bottom: black 2px solid; height: 35em">
<pre style="font-size: small; color: black; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ProgramHelloArguments
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">enum</span> GreetingType
        { Standard, Friendly, Familiar }
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">int</span>? _age;
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> _email;

    [EnumArgument(<span style="color: #006080">"say"</span>), HelpText(<span style="color: #006080">"Specify alternate greeting"</span>)]
    <span style="color: #0000ff">public</span> GreetingType Greeting = GreetingType.Standard;

    [CommandLineArgument(<span style="color: #006080">"name"</span>), Required, Position(1)]
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Name;

    [SwitchArgument(<span style="color: #006080">"kissAss"</span>)]
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> ComplimentUser;

    [CommandLineArgument(<span style="color: #006080">"email"</span>), Position(2)]
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Email
    {   get { <span style="color: #0000ff">return</span> _email; }
        set
        {   _email = <span style="color: #0000ff">value</span>;
            <span style="color: #0000ff">if</span> (!String.IsNullOrEmpty(_email))
                _email = <span style="color: #006080">"mailto:"</span> + _email;
        }
    }

    [ValidDirectoryArgument(<span style="color: #006080">"homeDir"</span>)]
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> HomeDir;

    [IntArgument(<span style="color: #006080">"age"</span>), HelpText(<span style="color: #006080">"Optionally specify your age"</span>)]
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span>? Age
    {   get { <span style="color: #0000ff">return</span> _age; }
        set
        {   <span style="color: #0000ff">if</span> (<span style="color: #0000ff">value</span> &lt; 0)
                <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentParseException(<span style="color: #006080">"Age cannot be less than zero"</span>);
            _age = <span style="color: #0000ff">value</span>;
        }
    }
}
</pre>
</div>
<div style="margin-top: 0.5em; float: right; margin-left: 1.5em; width: 15em">
<center><img style="border-right: black 2px solid; border-top: black 2px solid; border-left: black 2px solid; border-bottom: black 2px solid; text-align: center; xfloat: right; xmargin: 0.5em 0 0.5em 1em" height="194" alt="Goofy lookin' guy on a magic carpet" src="http://feelingsofwhite.com/wp-content/uploads/2008/07/magiccarpetride.jpg" width="147"></center></p>
<p><i><big>Join me on a magic carpet ride into simplicity</big></i> as I further describe some of the interesting highlights of how to use it, how it works. and how you can steal the code, make it your own and add the quirky bits unique to your situation.&nbsp; <strong>The full Visual Studio 2005 project code is available</strong>.</p>
</div>
<p><big><i>Admit it,</i></big> you can tell how its supposed to work just from reading the property declaration, right? Features worth mentioning listed below. (or let me <a href="http://feelingsofwhite.com/wp-content/uploads/2008/07/teasecode.png">draw you a picture</a> <a onclick="javascript:window.open('http://feelingsofwhite.com/wp-content/uploads/2008/07/teasecode.png', '_new','height=630,width=600')" href="javascript:void(0)"><small>[in a new window]</small></a>, if you prefer)</p>
<ul>
<li>Both fields and properties are supported.&nbsp; As are booleans (Switch), enums and nullable types
<li>Re-usable validation (e.g. ValidDirectory, IntArgument), I'll show how easy it is to plug in your attributes for custom validation
<li>Ad-hoc validation in property setters (e.g. Age), or ad-hoc re-interpretation of arguments (e.g. Email)
<li>Required parameter validation
<li>Use Position to pass parameters with out specifying the token (e.g. "CommandLineParsing.exe James"), or use tokens to pass parameters in any order
<li>Use HelpText for auto-generating parameter help files (e.g. "-?")
<li>Decorate properties of any class.&nbsp; Imagine your own hierarchy of parameter classes which could be re-used across many programs </li>
</ul>
<p><small>Note: The code's a tad too verbose to dump full contents into this article.&nbsp; I'll omit the boring shit and provide full code for download.&nbsp; The full code is better commented, but within this article I'll reduce or omit inline comments for brevity and discuss in paragraph form.</small></p>
<div style="clear: both"></div>
<p><span id="more-173"></span></p>
<h3 style="font-weight: bold; font-size: 180%; width: 20em">Y'all Know What Time It Is?</h3>
<p>The .Net libraries provide only limited parsing of arguments.&nbsp; It turns the command line into an array of strings, and in my experience parsing command lines is done differently in every situation, copy + pasted around and done half-assed except when required.&nbsp; I first had the idea of using attributes to describe the desired parsing a few years back, started coding a super-generic solution, then stopped.&nbsp; My current job has around 40+ batch exes, and when discussion recently turned to how we could improve the horrid inconsistent parsing situation, I revived my old idea, it took over a chunk of my free time, and ended here.</p>
<p>I've decided that a one-sized-fits-all parse is impossible.&nbsp; There are a frazillion variations on command line parsing, conflicting conventions, and perhaps you've already got a situation that this won't handle.&nbsp; For instance, we use "Exe name:value name:value" at my current job,&nbsp; cmd's attrib command accepts things like "attrib -r +hs /s", and in fact, I hate how .net parses strings into it's array and BAH HUMBUG!&nbsp; Forget it!!&nbsp; No fucking one-size-fits-all!!!&nbsp; I'll show you later where to swap out the parsing layer into something of your own choosing, but keep the binding and attributes layer, which is the interesting part anyways.</p>
<h3 style="font-weight: bold; font-size: 180%; width: 20em">Invocation is <i>simple</i></h3>
<p>If you're only interested in using the code I've already written, this is to show you there's nothing to fear. You've already seen an example of an interesting Arguments class. Let's see how simple the my sample program is. <b>You are not required to use this pattern</b>, it's just how I chose to use the Arguments class. </p>
<div style="border-right: black 2px solid; border-top: black 2px solid; margin-left: 5px; overflow: scroll; border-left: black 2px solid; width: 600px; border-bottom: black 2px solid; height: 15em">
<pre style="font-size: small; color: black; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ProgramHelloWorld
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ProgramHelloArguments
        { <span style="color: #008000">/* See above for Arguments Class */</span> }

    <span style="color: #0000ff">public</span> ProgramHelloArguments Arguments = <span style="color: #0000ff">new</span> ProgramHelloArguments();

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Run()
    {
        StringBuilder sb = <span style="color: #0000ff">new</span> StringBuilder();
        <span style="color: #0000ff">if</span> (Arguments.Greeting == ProgramHelloArguments.GreetingType.Friendly)
            sb.Append(<span style="color: #006080">"Hi "</span>);
        <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (Arguments.Greeting == ProgramHelloArguments.GreetingType.Familiar)
            sb.Append(<span style="color: #006080">"What's up "</span>);
        <span style="color: #0000ff">else</span>
            sb.Append(<span style="color: #006080">"Hello "</span>);
        sb.Append(Arguments.Name);
        <span style="color: #0000ff">if</span> (!String.IsNullOrEmpty(Arguments.Email))
            sb.Append(<span style="color: #006080">" ("</span> + Arguments.Email + <span style="color: #006080">')'</span>);
        <span style="color: #0000ff">if</span> (Arguments.ComplimentUser)
            sb.Append(<span style="color: #006080">", you are looking exceptionally good today!"</span>);
        Console.WriteLine(sb.ToString());
        <span style="color: #008000">// more code in the full example, but you get the idea</span>
    }
}
</pre>
</div>
<p>Next let's see the boilerplate to invoke it that program. The <b>highlights are the <span style="font-family: monospace">ArgumentBindings</span> and the <span style="font-family: monospace">ArgumentParser</span></b>. The rest is mere error trapping, plumbing and niceties. Notice there's a <i>binding</i> phase that's seperate from the <i>parsing</i> phase. </p>
<ul>
<li>Binding uses reflection to analyze your custom Arguments object and it's properties;
<ul>
<li>errors are the fault of the developer (e.g. decorating a non-boolean field with a a SwitchArgument).</li>
</ul>
<li>Parsing interprets the command line parameters and attempts to assign values to properties of the Arguments object;
<ul>
<li>errors are the fault of the user (e.g. omitting a required field)</li>
</ul>
</li>
</ul>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<div style="border-right: black 2px solid; border-top: black 2px solid; margin-left: 5px; overflow: scroll; border-left: black 2px solid; width: 600px; border-bottom: black 2px solid; height: 20em">
<pre style="font-size: small; color: black; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">internal</span> <span style="color: #0000ff">class</span> ExecutionEntryPoint
{
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args)
    {
        ProgramHelloWorld program = <span style="color: #0000ff">new</span> ProgramHelloWorld();
        <span style="color: #0000ff">try</span>
        {
            <span style="color: #008000">//Binding uses reflection to create a hash table of relevant information</span>
            ArgumentBindings bindings = <span style="color: #0000ff">new</span> ArgumentBindings(program.Arguments);

            <span style="color: #008000">//Parsing inspects the command line (args) assigns values to fields/properties</span>
            ArgumentParser parser = <span style="color: #0000ff">new</span> ArgumentParser(bindings);
            <span style="color: #0000ff">if</span> (parser.HelpSwitchSpecified(args))
                bindings.WriteHelpText();
            <span style="color: #0000ff">else</span>
            {
                parser.ParseAndAssign(args);
                program.Run();
            }
        }
        <span style="color: #0000ff">catch</span> (ArgumentParseException ex)
        {
            Console.WriteLine(String.Format(<span style="color: #006080">"Error: {0}"</span>, ex.Message));
            Console.WriteLine(String.Format(<span style="color: #006080">"Use {0} to get usage parameters"</span>, ArgumentParser.HelpSwitch));
        }
        <span style="color: #0000ff">catch</span> (Exception ex)
        {
            Console.WriteLine(String.Format(<span style="color: #006080">"Error: {0} [{1}]"</span>, ex.Message, ex.GetType().Name));
        }
    }
}</pre>
</div>
<p>So that's it, that's how to use this unholy beast. <i><big>Why are you showing me this boring junk</big></i> you scream? To stress the simplicity of usage. Spend your time marking up properties instead. After all, command line parsing <i>should</i> be simple.</p>
<h3 style="font-weight: bold; font-size: 180%; width: 20em">Arguing with Attributes</h3>
<p>I won't be dicussing the <span style="font-family: monospace">HelpText</span>, <span style="font-family: monospace">Required</span> and <span style="font-family: monospace">Position</span> attributes, which contain no logic. Let's jump instead right into the <span style="font-family: monospace">CommandLineArgument</span>. It is meant to decorate a string field <small>(or property)</small>. It is also <b>the base-class from which all other attributes descend</b>.</p>
<div style="border-right: black 2px solid; border-top: black 2px solid; margin-left: 5px; overflow: scroll; border-left: black 2px solid; width: 600px; border-bottom: black 2px solid">
<pre style="font-size: small; color: black; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff">[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> CommandLineArgumentAttribute : Attribute
{
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> <span style="color: #0000ff">string</span> _argumentToken;

    <span style="color: #0000ff">public</span> CommandLineArgumentAttribute(<span style="color: #0000ff">string</span> argumentToken)
    {
        _argumentToken = argumentToken;
    }

    <span style="color: #008000">// The token used when parsing the command line.  </span>
    <span style="color: #008000">//   eg. my.exe -token {value} -token {value}</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Token
        { get { <span style="color: #0000ff">return</span> _argumentToken; } }

    <span style="color: #008000">// Called during the bind process (when inspecting the reflected properties)</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> ValidateBind(MemberInfoAdapter member)
    {
        <span style="color: #0000ff">if</span> (!member.Type.IsAssignableFrom(<span style="color: #0000ff">typeof</span>(<span style="color: #0000ff">string</span>)))
            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentBindException(String.Format(<span style="color: #006080">"{0} '{1}' can only be applied to a property or field of type string"</span>, <span style="color: #0000ff">this</span>.GetType().Name, <span style="color: #0000ff">this</span>.Token));
    }

    <span style="color: #008000">// Should the parser interpret the subsequent command line as a value</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">bool</span> ExpectsValue(MemberInfoAdapter member)
    {
        <span style="color: #0000ff">return</span> <span style="color: #0000ff">true</span>;
    }

    <span style="color: #008000">// called during the parse phase when a command line is encountered</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> SetValue(MemberInfoAdapter member, <span style="color: #0000ff">object</span> obj, <span style="color: #0000ff">string</span> <span style="color: #0000ff">value</span>)
    {
        member.SetValue(obj, <span style="color: #0000ff">value</span>);
    }

    <span style="color: #008000">/// displayed to user during help text generation.  descendants can override to be more descriptive</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">string</span> GetHelpTextValue(MemberInfoAdapter member)
        { <span style="color: #0000ff">return</span> <span style="color: #006080">"&lt;value&gt;"</span>; }
}
</pre>
</div>
<p>What the heck is a <span style="font-family: monospace">MemberInfoAdapter</span>? <small>(seen referenced in <span style="font-family: monospace">SetValue</span>)</small> </p>
<ul>
<li>It's an uninteresting class allowing us to do things like <span style="font-family: monospace">SetValue</span>, or obtain the <span style="font-family: monospace">Type</span>.
<li>Works for both <span style="font-family: monospace">FieldInfo</span> or <span style="font-family: monospace">PropertyInfo</span> object.
<ul>
<li>The two classes both support such operations, but do not share enough ancestory, or a common interface.</li>
</ul>
<li>The adapter simplifies the Argument classes, allowing them to easily support both fields and properties.</li>
</ul>
<p>As discussed in the Invocation section, there is a serpate binding phase. The <span style="font-family: monospace">ValidateBind</span> method provides a way for argument classes to validate they've been applied to a field of the correct type, or any other validation you can think of, based on the reflection information. The <span style="font-family: monospace">CommandLineArgument</span>, displayed above, provides a good example of a <span style="font-family: monospace">ValidateBind</span> implementation.</p>
<p>Let's examine the <span style="font-family: monospace"><b>EnumArgument</b></span>'s <span style="font-family: monospace">ValidateBind</span> for a bit of contrast. </p>
<ul>
<li>It's meant to be applied to any enumerated type, used to restrict values accepted from user input.
<li><span style="font-family: monospace">SetValue</span> translates a string to the proper enumerated value
<li><span style="font-family: monospace">GetHelpTextValue</span>, returns a descriptive string, displayed during "my.exe -?" type operations</li>
</ul>
<div style="border-right: black 2px solid; border-top: black 2px solid; margin-left: 5px; overflow: scroll; border-left: black 2px solid; width: 600px; border-bottom: black 2px solid; height: 15em">
<pre style="font-size: small; color: black; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> EnumArgumentAttribute : CommandLineArgumentAttribute
{
    <span style="color: #0000ff">public</span> EnumArgumentAttribute(<span style="color: #0000ff">string</span> argumentToken) : <span style="color: #0000ff">base</span>(argumentToken) { }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> ValidateBind(MemberInfoAdapter member)
    {
        <span style="color: #0000ff">if</span> (!member.Type.IsEnum)
            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentBindException(String.Format(<span style="color: #006080">"{0} '{1}' can only be applied to an enumerated property or field"</span>, <span style="color: #0000ff">this</span>.GetType().Name, <span style="color: #0000ff">this</span>.Token));
    }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> SetValue(MemberInfoAdapter member, <span style="color: #0000ff">object</span> obj, <span style="color: #0000ff">string</span> <span style="color: #0000ff">value</span>)
    {
        <span style="color: #0000ff">object</span> enumvalue;
        <span style="color: #0000ff">try</span>
        {
            enumvalue = Enum.Parse(member.Type, <span style="color: #0000ff">value</span>, <span style="color: #0000ff">true</span>);
        }
        <span style="color: #0000ff">catch</span> (ArgumentException ex)
        {
            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentParseException(String.Format(<span style="color: #006080">"'{0}' is not valid, must be one of {1}"</span>, <span style="color: #0000ff">value</span>, GetHelpValue(member)), ex);
        }
        member.SetValue(obj, enumvalue);
    }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">string</span> GetHelpTextValue(MemberInfoAdapter member)
    {
        StringBuilder sb = <span style="color: #0000ff">new</span> StringBuilder(<span style="color: #006080">"{"</span>);
        <span style="color: #0000ff">bool</span> isFirst = <span style="color: #0000ff">true</span>;
        <span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> memberName <span style="color: #0000ff">in</span> Enum.GetNames(member.Type))
        {
            <span style="color: #0000ff">if</span> (!isFirst)
                sb.Append(<span style="color: #006080">", "</span>);
            isFirst = <span style="color: #0000ff">false</span>;
            sb.Append(memberName);
        }
        sb.Append(<span style="color: #006080">"}"</span>);
        <span style="color: #0000ff">return</span> sb.ToString();
    }
}
</pre>
</div>
<p>If all properties successfully bind, we move onto the parsing phase. The <span style="font-family: monospace"><b>SetValue</b></span> method will be called with details the user entered on the command line. This is where value <b>validation or re-interpretation</b> can occur. For example, you might ensure a numeric UserId actually exists in a database before assigning it the property. Taking it further, you might accept a UserId but assign a UserName to the object's property.</p>
<p>Here's a descendant property that ensures the user specifies a valid directory:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<div style="border-right: black 2px solid; border-top: black 2px solid; margin-left: 5px; overflow: scroll; border-left: black 2px solid; width: 600px; border-bottom: black 2px solid">
<pre style="font-size: small; color: black; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ValidDirectoryArgument : CommandLineArgumentAttribute
{
    <span style="color: #0000ff">public</span> ValidDirectoryArgument(<span style="color: #0000ff">string</span> argumentToken) : <span style="color: #0000ff">base</span>(argumentToken) { }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> SetValue(MemberInfoAdapter member, <span style="color: #0000ff">object</span> obj, <span style="color: #0000ff">string</span> <span style="color: #0000ff">value</span>)
    {
        <span style="color: #0000ff">if</span> (!System.IO.Directory.Exists(<span style="color: #0000ff">value</span>))
            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentParseException(String.Format(<span style="color: #006080">"'{0}' is not a valid directory"</span>, <span style="color: #0000ff">value</span>));
        member.SetValue(obj, <span style="color: #0000ff">value</span>);
    }
}</pre>
</div>
<p>Finally, the <span style="font-family: monospace">ExpectsValue</span> is meant primarily for the <span style="font-family: monospace">SwitchArgument</span>, or switch-like arguments. It allows "my.exe -recursive" instead of a clunkier "my.exe -recursive true". It allows helps the parser determine wether "my.exe -nice -6", means "token <i>nice</i> has a value of -6" or "token <i>nice</i> exists; token <i>6</i> exists" (or "token <i>nice</i> exists; <i>unamed value</i> of -6 exists, use positional logic). Likely the <span style="font-family: monospace">SwitchArgument</span>'s <span style="font-family: monospace">bool</span> support is all you'll ever need, but perhaps you can imagine arguments that do something else within <span style="font-family: monospace">SetValue</span>?</p>
<p>&nbsp;&nbsp; <img height="146" alt="Visual repetition of the possible variable interpretations" src="http://feelingsofwhite.com/wp-content/uploads/2008/07/switcharguments.png" width="589"></p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<div style="border-right: black 2px solid; border-top: black 2px solid; margin-left: 5px; overflow: scroll; border-left: black 2px solid; width: 600px; border-bottom: black 2px solid; height: 14em">
<pre style="font-size: small; color: black; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> SwitchArgumentAttribute : CommandLineArgumentAttribute
{
    <span style="color: #0000ff">public</span> SwitchArgumentAttribute(<span style="color: #0000ff">string</span> argumentToken) : <span style="color: #0000ff">base</span>(argumentToken) { }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">bool</span> ExpectsValue(MemberInfoAdapter member)
    {
        <span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;
    }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> SetValue(MemberInfoAdapter member, <span style="color: #0000ff">object</span> obj, <span style="color: #0000ff">string</span> <span style="color: #0000ff">value</span>)
    {
        member.SetValue(obj, <span style="color: #0000ff">true</span>);
    }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> ValidateBind(MemberInfoAdapter member)
    {
        <span style="color: #0000ff">if</span> (!member.Type.IsAssignableFrom(<span style="color: #0000ff">typeof</span>(<span style="color: #0000ff">bool</span>)))
            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentBindException(String.Format(<span style="color: #006080">"{0} '{1}' can only be applied to a property or field of type bool"</span>, <span style="color: #0000ff">this</span>.GetType().Name, <span style="color: #0000ff">this</span>.Token));
    }
}</pre>
</div>
<h3 style="font-weight: bold; font-size: 180%; width: 20em">Final Thoughts &amp; Download</h3>
<p>That's all that's required to use it. If you curious about the the technical workings of Binding &amp; Parsing, read through the appendix. If you have customized parsing requirements or are integrating into an existing framework you'll want to take a look for sure. This code is very much a receipe, feel free to download, tweak and customize it to your heart's content. I've also listed included a <em>Future Enhancements</em> appendix, with some ideas of how to build on the command line parsing that I've alredy written.</p>
<p>I've tried to be brief, and there are much more comments in the included code. Feel free to use it, modify it, etc. Just include a link back to this webpage in the source, and maybe drop me a comment to let me know you found this useful. There's a lot here, and we've found it useful base at my current work. Its unlikely you have a command line project now, but one day you will. <strong>Next time you're faced with a command line, remember <em>Feelings of White</em></strong>, come back and grab the code that will save you mountains of time.</p>
<p><a href="http://feelingsofwhite.com/wp-content/uploads/2008/07/commandlineparsing.zip" target="_blank">Download full source: CommandLineParsing.zip</a></p>
<h3 style="font-weight: bold; font-size: 180%; width: 20em"><small>Appendix A: </small>Future Enhancements</h3>
<ul>
<li>As mentioned in Appendix B, <strong>the <span style="font-family: monospace">ArgumentParser</span> is most likely the bit you'll need to improve/replace</strong>, to fit your unique situation.&nbsp; It might be that some of the simpler choices I've made won't fit your need.&nbsp;
<ul>
<li>You might need to <b>allow Argument Attributes to participate in the parsing process themselves</b>.&nbsp; While this makes a tighter coupling of parse &amp; attributes, it also allows things like both "-r42" and "-r 42", allowing the attribute to determine dynamically whether it expects a value.&nbsp; The waters have already been muddied by the <span style="font-family: monospace">ExpectsValue</span> and <span style="font-family: monospace">GetHelpTextValue</span>
<li><b>You might have a radically different parse algorithm</b> (e.g. "name:value" format), values mixed with attributes (e.g. "-r42"), multiple switches being set within a single string (e.g. "+rh -s"), or any other things you can think of. </li>
</ul>
<li><b>There are many generic <span style="font-family: monospace">CommandLineArgument</span> descendants that could be written</b>, left as an exercise for the reader.&nbsp; Some ideas: Date Parsing, Float parsing, allowing comma,seperate,lists to be written to a List&lt;string&gt; property as well as <b>your own domain specific attributes (the CustomerID attribute, etc)</b>
<li>A better automated help text generation system could be written.&nbsp; I included it both for simple convenience, but also as an example of what else you could do with the Binding metadata gathered. </li>
</ul>
<h3 style="font-weight: bold; font-size: 180%; width: 20em"><small>Appendix B: </small>Binding &amp; Parsing</h3>
<p>You may be curious about what translates the argument attributes into useful calls to the custom arguments class.&nbsp; Let's take a look at the binding and parsing phase in more depth.&nbsp; I've removed quite a bit of extra code from the <span style="font-family: monospace">ArgumentBindings</span> excerpt below, to better focus on the <span style="font-family: monospace">BindMember</span> method <small>(you'll have to scroll down a bit)</small>.&nbsp; In essence, it's doing a few <span style="font-family: monospace">System.Reflection</span>&nbsp; calls to determine the attributes decorated from a <span style="font-family: monospace">_argumentObject</span>, our custom parameter object, and parsing them into a Dictionary to make the information a little easier to deal with.&nbsp; </p>
<div style="border-right: black 2px solid; border-top: black 2px solid; margin-left: 5px; overflow: scroll; border-left: black 2px solid; width: 600px; border-bottom: black 2px solid; height: 30em">
<pre style="font-size: small; color: black; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ArgumentBindings : IArgumentAssignment
{
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> <span style="color: #0000ff">bool</span> _ignoreCase;
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> <span style="color: #0000ff">object</span> _argumentObject;
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> Dictionary&lt;<span style="color: #0000ff">string</span>, ArgumentBindingInfo&gt; _argumentHash = <span style="color: #0000ff">new</span> Dictionary&lt;<span style="color: #0000ff">string</span>, ArgumentBindingInfo&gt;();
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> SortedList&lt;<span style="color: #0000ff">int</span>, ArgumentBindingInfo&gt; _positionalArguments = <span style="color: #0000ff">new</span> SortedList&lt;<span style="color: #0000ff">int</span>, ArgumentBindingInfo&gt;();

    <span style="color: #0000ff">private</span> <span style="color: #0000ff">class</span> ArgumentBindingInfo
    {
        <span style="color: #0000ff">public</span> CommandLineArgumentAttribute ArgumentAttribute;
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> Required;
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> Specified = <span style="color: #0000ff">false</span>;
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> HelpText;
        <span style="color: #0000ff">public</span> MemberInfoAdapter Adapter;
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span>? PositionIndex;
    }

    <span style="color: #008000">// called by constructor (ctor omitted from this snippet)</span>
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> Bind()
    {
        <span style="color: #0000ff">foreach</span> (MemberInfo memberInfo <span style="color: #0000ff">in</span> GetFieldsAndProperties(_argumentObject.GetType()))
        {
            CommandLineArgumentAttribute argumentAttribute;
            <span style="color: #0000ff">if</span> (GetSingleAttribute(memberInfo, <span style="color: #0000ff">out</span> argumentAttribute))
                BindMember(memberInfo, argumentAttribute);
        }
    }

    <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> BindMember(MemberInfo memberInfo, CommandLineArgumentAttribute argumentAttribute)
    {
        ArgumentBindingInfo argument = <span style="color: #0000ff">new</span> ArgumentBindingInfo();
        argument.Adapter = MemberInfoAdapter.Create(memberInfo);
        argument.ArgumentAttribute = argumentAttribute;
        argument.ArgumentAttribute.ValidateBind(argument.Adapter);
        argument.Required = memberInfo.IsDefined(<span style="color: #0000ff">typeof</span>(RequiredAttribute), <span style="color: #0000ff">false</span>);

        PositionAttribute positionAttribute;
        <span style="color: #0000ff">if</span> (GetSingleAttribute(memberInfo, <span style="color: #0000ff">out</span> positionAttribute))
            argument.PositionIndex = positionAttribute.Index;

        <span style="color: #0000ff">if</span> (argument.PositionIndex != <span style="color: #0000ff">null</span>)
        {
            <span style="color: #0000ff">if</span> (!argument.ArgumentAttribute.ExpectsValue(argument.Adapter))
                <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentBindException(String.Format(<span style="color: #006080">"'{0}' cannot have a position, because {1} does accept values"</span>,
                                                              argument.Adapter.Name,
                                                              argument.ArgumentAttribute.GetType().Name));
            ArgumentBindingInfo existing;
            <span style="color: #0000ff">if</span> (_positionalArguments.TryGetValue(argument.PositionIndex.Value, <span style="color: #0000ff">out</span> existing))
                <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentBindException(
                    String.Format(<span style="color: #006080">"Position '{0}' registered to both '{1}' and '{2}'"</span>,
                                  argument.PositionIndex,
                                  existing.Adapter.Name,
                                  argument.Adapter.Name));
            _positionalArguments.Add(argument.PositionIndex.Value, argument);
        }

        HelpTextAttribute helpTextAttribute;
        <span style="color: #0000ff">if</span> (GetSingleAttribute(memberInfo, <span style="color: #0000ff">out</span> helpTextAttribute))
            argument.HelpText = helpTextAttribute.Text;

        <span style="color: #0000ff">string</span> token = argument.ArgumentAttribute.Token;
        <span style="color: #0000ff">if</span> (_ignoreCase)
            token = token.ToLower();
        _argumentHash.Add(token, argument);
    }

    <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">bool</span> GetSingleAttribute&lt;T&gt;(MemberInfo memberInfo, <span style="color: #0000ff">out</span> T match) <span style="color: #0000ff">where</span> T : <span style="color: #0000ff">class</span>
    {
        <span style="color: #008000">//If you're curious: </span>
        <span style="color: #008000">//  if AttributeUsage's AllowMultiple=True, Child's attribute is 0, Base's attributes is Length-1</span>
        <span style="color: #008000">//  if AllowMultiple=False [default], Subsequent usages of an attribute (eg HelpText) replace previous ones</span>
        <span style="color: #008000">//  For non-sealed classes (eg CommandlineArgumentAttribute), it is possible to have multiple</span>
        <span style="color: #008000">//  returned, as attribute descendants of the attribute can be applied.  </span>
        T[] attributes = (T[])memberInfo.GetCustomAttributes(<span style="color: #0000ff">typeof</span>(T), <span style="color: #0000ff">true</span>);
        <span style="color: #0000ff">switch</span> (attributes.Length)
        {
            <span style="color: #0000ff">case</span> 0:
                match = <span style="color: #0000ff">null</span>;
                <span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;
            <span style="color: #0000ff">case</span> 1:
                match = attributes[0];
                <span style="color: #0000ff">return</span> <span style="color: #0000ff">true</span>;
            <span style="color: #0000ff">default</span>:
                <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentBindException(
                    String.Format(<span style="color: #006080">"Member '{0}' has multiple {1} attributes or descendants"</span>,
                                  memberInfo.Name, <span style="color: #0000ff">typeof</span>(T).Name));
        }
    }

    <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> IEnumerable&lt;MemberInfo&gt; GetFieldsAndProperties(Type type)
    {
        <span style="color: #0000ff">foreach</span> (FieldInfo info <span style="color: #0000ff">in</span> type.GetFields())
            <span style="color: #0000ff">yield</span> <span style="color: #0000ff">return</span> info;
        <span style="color: #0000ff">foreach</span> (PropertyInfo info <span style="color: #0000ff">in</span> type.GetProperties())
            <span style="color: #0000ff">yield</span> <span style="color: #0000ff">return</span> info;
    }

    <span style="color: #008000">// Note: Many methods omitted for brevity</span>
}
</pre>
</div>
<p>As I mentioned, there are many more methods omitted from this article which appear in the full code.&nbsp; Chiefly I've skipped the <span style="font-family: monospace">WriteHelpText</span> method mentioned during the invocation boilerplate <small>(it loops through the <span style="font-family: monospace">_argumentHash</span> and displays the strings captured by <span style="font-family: monospace">HelpText</span>)</small>.&nbsp; Also skipped is the implementation details of the <span style="font-family: monospace">IArgumentAssignment</span>:</p>
<div style="border-right: black 2px solid; border-top: black 2px solid; margin-left: 5px; overflow: scroll; border-left: black 2px solid; width: 600px; border-bottom: black 2px solid">
<pre style="font-size: small; color: black; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">public</span> <span style="color: #0000ff">enum</span> ArgumentAssignmentType
    {  Unknown, Switch, NameValue  }

<span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> IArgumentAssignment
{
    ArgumentAssignmentType GetArgumentType(<span style="color: #0000ff">string</span> token);
    <span style="color: #0000ff">void</span> SetArgumentValue(<span style="color: #0000ff">string</span> token, <span style="color: #0000ff">string</span> <span style="color: #0000ff">value</span>);
    <span style="color: #0000ff">void</span> SetPositionalArgument(<span style="color: #0000ff">string</span> <span style="color: #0000ff">value</span>);
    <span style="color: #0000ff">void</span> FinishedParsing();
}
</pre>
</div>
<p>The <span style="font-family: monospace">IArgumentAssignment</span> is the contract by which the Parser interacts with the Binding information.&nbsp; Calls to <span style="font-family: monospace">GetArgumentType</span> use the hash and <span style="font-family: monospace">CommandLineArgument</span>'s <span style="font-family: monospace">ExpectValue</span> to determine the result, the next two are passthroughs to the <span style="font-family: monospace">SetValue</span>, while <span style="font-family: monospace">FinishedParsing</span> just ensures that all Required fields are specified.&nbsp; </p>
<p>I don't feel this article could be complete without including <b>the parsing code</b> that shows the interaction between command line and the bindings.&nbsp; But at the same time it's merely Yet Another String Parsing Problem.&nbsp; I'll leave discussion on it's future potential to another day's session.&nbsp; Feel free to skip the next code block, unless the nitty gritty of the argument parse are your cup of tea.&nbsp; <b>It's also the most likely candidate for your customization and/or replacement</b> by you.</p>
<div style="border-right: black 2px solid; border-top: black 2px solid; margin-left: 5px; overflow: scroll; border-left: black 2px solid; width: 600px; border-bottom: black 2px solid; height: 20em">
<pre style="font-size: small; color: black; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #008000">// Strings are expected to be in the form:</span>
<span style="color: #008000">///   -name1 {value} -switchA -name2 {value} -name3 {value}</span>
<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ArgumentParser
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> SwitchPrefix = <span style="color: #006080">"-"</span>;
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> HelpSwitch = SwitchPrefix + <span style="color: #006080">"?"</span>;
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> IArgumentAssignment _argumentAssignment;

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> ParseAndAssign(<span style="color: #0000ff">string</span>[] args)
    {
        Queue&lt;<span style="color: #0000ff">string</span>&gt; positional = <span style="color: #0000ff">new</span> Queue&lt;<span style="color: #0000ff">string</span>&gt;();
        <span style="color: #0000ff">int</span> i = 0;
        <span style="color: #0000ff">while</span> (i &lt; args.Length)
        {
            <span style="color: #0000ff">string</span> token = <span style="color: #0000ff">null</span>;
            ArgumentAssignmentType argumentAssignmentType = ArgumentAssignmentType.Unknown;
            <span style="color: #0000ff">if</span> (args[i].Substring(0, 1) == SwitchPrefix)
            {
                token = args[i].Substring(1);
                argumentAssignmentType = _argumentAssignment.GetArgumentType(token);
            }
            <span style="color: #0000ff">switch</span> (argumentAssignmentType)
            {
                <span style="color: #0000ff">case</span> ArgumentAssignmentType.Switch:
                    _argumentAssignment.SetArgumentValue(token, <span style="color: #0000ff">null</span>);
                    <span style="color: #0000ff">break</span>;
                <span style="color: #0000ff">case</span> ArgumentAssignmentType.NameValue:
                    <span style="color: #0000ff">if</span> (i + 1 == args.Length)
                        <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentParseException(
                            String.Format(<span style="color: #006080">"Argument '{0}' requires a value"</span>, token));
                    <span style="color: #0000ff">else</span>
                    {
                        _argumentAssignment.SetArgumentValue(token, args[i + 1]);
                        i++;
                    }
                    <span style="color: #0000ff">break</span>;
                <span style="color: #0000ff">case</span> ArgumentAssignmentType.Unknown:
                    positional.Enqueue(args[i]);
                    <span style="color: #0000ff">break</span>;
            }
            i++;
        }
        <span style="color: #0000ff">while</span> (positional.Count &gt; 0)
            _argumentAssignment.SetPositionalArgument(positional.Dequeue());
        _argumentAssignment.FinishedParsing();
    }

    <span style="color: #008000">//ctor and HelpSwitchSpecified are omitted</span>
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2008/07/command-line-parsing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress plugin: Apply a CSS class defined in a post&#8217;s custom field</title>
		<link>http://feelingsofwhite.com/2008/05/legions-div-content-plugin/</link>
		<comments>http://feelingsofwhite.com/2008/05/legions-div-content-plugin/#comments</comments>
		<pubDate>Fri, 23 May 2008 04:36:08 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[technical]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[the process]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://FeelingsOfWhite.com/2008/05/legions-div-content-plugin/</guid>
		<description><![CDATA[A wordpress plugin I wrote to surround the_content with a div class="of your choosing".]]></description>
			<content:encoded><![CDATA[<p>It's not much, but it's helped the look of my site.&nbsp; By applying a custom field to a specific blog post like so:</p>
<p><img style="border-right: black 2px solid; border-top: black 2px solid; border-left: black 2px solid; border-bottom: black 2px solid" height="117" alt="WordPress admin screenshot, showing a custom field with a key of &quot;legioncss&quot; and a value of &quot;MyCssClass&quot;" src="http://feelingsofwhite.com/wp-content/uploads/2008/05/image4.png" width="406" border="2"></p>
<p>Your content (regardless of index, archive, or single placement) then renders like so:</p>
<p class="legioncode">&lt;div class="MyCssClass"&gt;Actual Blog Post Here&lt;/div&gt;</p>
<p>This allows each post to have different (but common) CSS Styles.&nbsp; Other plugins allow you to apply a custom stylesheet per-post, but my plugin is more useful when there are a few common styles you want to re-used.&nbsp; All that's missing is uploading the following code to your <font face="Monospace">wp-content/plugins</font> directory:</p>
<pre class="legioncode">&lt;?php

<font color="#808080">/**
 Plugin Name: Legion's Div Content Plugin
 Version: 0.1
 Description: Wraps the the_content with a custom css class specified in the "legioncss" custom field
 Author: legion
 Author URI: http://FeelingsOfWhite.com
 */</font>

add_filter(<font color="#008000">'the_content'</font>, <font color="#008000">'legiondiv_the_content'</font>);

function legiondiv_the_content($content) {
    global $post;  <font color="#808080">//required to access $post-&gt;ID
</font>    $customCssClass = get_post_meta($post-&gt;ID, <font color="#008000">"legioncss"</font>, true);
    if ($customCssClass != <font color="#008000">""</font>)
        $content = <font color="#008000">'&lt;div class="'</font> . $customCssClass . <font color="#008000">'"&gt;'</font> . <font color="#008000">"$content&lt;/div&gt;"</font>;
    return $content;
}

?&gt;</pre>
<p>As a n00b to WordPress, it's hackability has impressed me.&nbsp; I'm amazed that this is all it takes to write a plugin.&nbsp; There are plenty of fantastic resources available just by searching the web.</p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2008/05/legions-div-content-plugin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>TortoiseSVN + Command Line</title>
		<link>http://feelingsofwhite.com/2008/01/tortoisesvn-command-line/</link>
		<comments>http://feelingsofwhite.com/2008/01/tortoisesvn-command-line/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 23:38:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[TortoiseSVN]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2008/01/31/tortoisesvn-command-line/</guid>
		<description><![CDATA[TortoiseSVN is a well loved shell integration tool, and if you’re into both the Windows and the Subversion, chances are excellent that you’re already using it.  But did you know this brilliant GUI has a dark side?  What else would I love about Tortoise but its command line support!  I finally dug [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tortoisesvn.tigris.org/">TortoiseSVN</a> is a well loved shell integration tool, and if you’re into both the Windows and the <a href="http://subversion.tigris.org/">Subversion</a>, chances are excellent that you’re already using it.  But did you know this brilliant GUI has a dark side?  What else would I love about Tortoise but its <strong>command line support</strong>!  I finally dug in and made some powershell friendly wrappers around the commands I cared about.</p>
<p>If you’re often hanging around the command line, as I do, it’s such a drag to open an explorer window, just so you can right click on a file to bring up the visual diff.  (If you can read complex diffs without the need for a gui, you’re a better dev than I)  How lovely to simply type</p>
<blockquote><p><code>tdiff myFile.txt </code></p></blockquote>
<p>and have the visual diff launch.  Or the visual log viewer, or the interactive commit dialog.  I find they go hand in hand with the already brilliant svn command set.</p>
<p>You can also get fancy.  How about bringing up the diff and/or conflict dialog for every modified or conflicted file.  Perfect for code review situations<br />
<blockquote><code>svn status | select-string "^[MC]" | %{ tdiff $_.Line.SubString(7) }</code></p></blockquote>
<p>As you’re about to see, I’m not doing much besides wrapping what’s already there.  The key points are the /notempfile (if you don’t, path might be deleted according to the docs), and that the path must be a full path.  Enjoy the idea or the code, which ever you take away</p>
<pre>
$TortoiseProc = 'C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe'

function myExpandPath($path, $prefix="path")
{
    if ($path -match "^((https?)|(svn(\+ssh)?)|(file))\:\/\/") {
        <font color="darkgray">#path has been fully specified (e.g. http://server/foo or file:///C:/foo)</font>
        return "/$prefix" + ":""$path"""
    } else {
        <font color="darkgray">#path is a local name</font>
        return "/$prefix" + ":""" + (Get-Item $path).FullName + '"'
    }
}

function RepoBrowser-TortoiseSvn ($path=".")
{
    &amp;$TortoiseProc "/command:repobrowser" (myExpandPath $path) "/notempfile"
}

function Commit-TortoiseSvn ($path=".")
{
    &amp;$TortoiseProc "/command:commit" (myExpandPath $path) "/notempfile"
}

function ConflictEditor-TortoiseSvn ($path=".")
{
    &amp;$TortoiseProc "/command:conflicteditor" (myExpandPath $path) "/notempfile"
}

function Diff-TortoiseSvn ($path=".", $path2)
{
    if ($path2 -ne $null) {
        $path2 = myExpandPath $path2 -prefix 'path2'
    }
    &amp;$TortoiseProc "/command:diff" (myExpandPath $path) $path2 "/notempfile"
}

function SmartDiff-TortoiseSvn ($path=".", $path2)
{
    <font color="darkgray">#If a file in conflict, use ConflictEditor, otherwise use Diff</font>
    if (($path2 -eq $null) -and
        (!(get-item $path).PsIsContainer) -and
        ((svn status $path)[0] -eq 'C')) {
        return ConflictEditor-TortoiseSvn $path
    }
    return Diff-TortoiseSvn -path:$path -path2:$path2
}

function Status-TortoiseSvn ($path=".")
{
    &amp;$TortoiseProc "/command:repostatus" (myExpandPath $path) "/notempfile"
}

function Log-TortoiseSvn ($path=".")
{
    &amp;$TortoiseProc "/command:log" (myExpandPath $path) "/notempfile" $strictSwitch
}

Set-Alias tstatus   Status-TortoiseSvn
Set-Alias tdiff     SmartDiff-TortoiseSvn
Set-Alias tbrowse   RepoBrowser-TortoiseSvn
Set-Alias tcommit   Commit-TortoiseSvn
Set-Alias tlog      Log-TortoiseSvn
</pre>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2008/01/tortoisesvn-command-line/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Powershell 2.0 CTP</title>
		<link>http://feelingsofwhite.com/2007/12/powershell-20-ctp/</link>
		<comments>http://feelingsofwhite.com/2007/12/powershell-20-ctp/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 16:03:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[mlp]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/12/13/powershell-20-ctp/</guid>
		<description><![CDATA[Powershell 2.0 CTP has been released, download link enclosed.]]></description>
			<content:encoded><![CDATA[<p><i>ohmygod ohmygod ohmygod</i></p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=60deac2b-975b-41e6-9fa0-c2fd6aa6bc89&amp;displaylang=en">The PowerShell goodness has evolved</a>.  I haven't installed it yet, but will do so asap.  I'm currently working up a proof of concept CVSNT to SVN conversion for our shop, so this is some good timing.</p>
<p><small>(via <a href="http://tfl09.blogspot.com/2007/11/windows-powershell-20-ctp-available-for.html">Under The Stairs</a>)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/12/powershell-20-ctp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Big-O Notation</title>
		<link>http://feelingsofwhite.com/2007/10/big-o-notation/</link>
		<comments>http://feelingsofwhite.com/2007/10/big-o-notation/#comments</comments>
		<pubDate>Wed, 03 Oct 2007 19:43:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[technical]]></category>
		<category><![CDATA[mlp]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/10/03/big-o-notation/</guid>
		<description><![CDATA[Coding Horror has a lovely treatment of Big-O notation called Everything Is Fast For Small n.  I R SMRTr now.
(via Vlad)
]]></description>
			<content:encoded><![CDATA[<p>Coding Horror has a lovely treatment of Big-O notation called <a href="http://www.codinghorror.com/blog/archives/000957.html">Everything Is Fast For Small n</a>.  I R SMRTr now.</p>
<p><small>(via <a href="http://wwww.analogcoast.com">Vlad</a>)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/10/big-o-notation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Powershell Help Files</title>
		<link>http://feelingsofwhite.com/2007/06/powershell-help-files/</link>
		<comments>http://feelingsofwhite.com/2007/06/powershell-help-files/#comments</comments>
		<pubDate>Fri, 08 Jun 2007 20:13:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[mlp]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/06/08/powershell-help-files/</guid>
		<description><![CDATA[
Print able Quick Reference Guide for your printing pleasure
Graphic help file same contents as the commandline help, bundled as a searchable windows help file with hyperlinks and fun such goodness.
Online Quick Reference Page for online reference

(first two via Powershell  Guy)
]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://www.microsoft.com/downloads/details.aspx?familyid=df8ed469-9007-401c-85e7-46649a32d0e0&amp;displaylang=en&amp;tm">Print able Quick Reference Guide</a> for your printing pleasure</p>
<li><a href="http://www.microsoft.com/downloads/details.aspx?familyid=3b3f7ce4-43ea-4a21-90cc-966a7fc6c6e8&amp;displaylang=en&amp;tm">Graphic help file</a> same contents as the commandline help, bundled as a searchable windows help file with hyperlinks and fun such goodness.
<li><a href="http://channel9.msdn.com/wiki/default.aspx/Channel9.WindowsPowerShellQuickStart">Online Quick Reference Page</a> for online reference
</ul>
<p>(first two via <a href="http://thepowershellguy.com/blogs/posh/archive/2007/06/03/powershell-quick-reference.aspx">Powershell </a> <a href="http://thepowershellguy.com/blogs/posh/archive/2007/06/03/powershell-quick-reference.aspx">Guy</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/06/powershell-help-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Download Heroes Comix with the PowerShell Goodness</title>
		<link>http://feelingsofwhite.com/2007/05/download-heroes-comix-with-the-powershell-goodness/</link>
		<comments>http://feelingsofwhite.com/2007/05/download-heroes-comix-with-the-powershell-goodness/#comments</comments>
		<pubDate>Wed, 02 May 2007 15:45:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[the arts]]></category>
		<category><![CDATA[heroes]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/05/02/download-heroes-comix-with-the-powershell-goodness/</guid>
		<description><![CDATA[Are you a Heroes fan? One that's not afraid to run a powershell script? And
someone who reads my blog?&#160; If you're still reading, then today's your
lucky day!&#160; Here's a snippet I used to download the supplementary heroes
comics.&#160; Clicking hyperlinks with a mouse is for chumps! I didn't
bother to figure out how to auto-detect the number [...]]]></description>
			<content:encoded><![CDATA[<p>Are you a Heroes fan? One that's not afraid to run a powershell script? And<br />
someone who reads my blog?&nbsp; If you're still reading, then today's your<br />
lucky day!&nbsp; Here's a snippet I used to download the supplementary heroes<br />
comics.&nbsp; Clicking hyperlinks with a mouse is for <i>chumps!</i> I didn't<br />
bother to figure out how to auto-detect the number of available novels, so you<br />
just gotta change the $number variable yerself.&nbsp; </p>
<pre style="overflow:scroll;max-width:600px;">
<font face="Courier New">$numbers = 1..31 <font color="#808080">#check out <a href="http://www.nbc.com/Heroes/novels/novels_library.shtml">http://www.nbc.com/Heroes/novels/novels_library.shtml</a> to see how many are online</font>

$downloadFolder = &quot;c:\Download\HeroesNovels&quot; ;

$downloadFolder | %{ if (!(test-path $_)) { md $_ | out-null } } ;

$webclient = new-object System.Net.WebClient ;
$numbers = $numbers | %{ $_.ToString().PadLeft(3, &quot;0&quot;) } |
&nbsp;&nbsp;&nbsp; where { (!(test-path &quot;$downloadFolder\Heroes_novel_$_.pdf&quot;))
}

if ($numbers) { <font color="#808080">#FYI: same as saying ($numbers -ne $null)
</font>&nbsp;&nbsp;&nbsp; $i=0;
&nbsp;&nbsp;&nbsp; $numbers | %{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $i++;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-progress &quot;Downloading&quot; &quot;Heroes&quot; -percent ($i / $numbers.count * 100) ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $webclient.DownloadFile(&quot;http://www.nbc.com/Heroes/novels/downloads/Heroes_novel_$_.pdf&quot;, &quot;$downloadFolder\Heroes_novel_$_.pdf&quot;) ;
&nbsp;&nbsp;&nbsp; } ;
&nbsp;&nbsp;&nbsp; Write-Progress &quot;Downloading&quot; &quot;Heroes&quot; -completed
}</font></pre>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/05/download-heroes-comix-with-the-powershell-goodness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Look what you can do in Powershell: FTP!</title>
		<link>http://feelingsofwhite.com/2007/03/look-what-you-can-do-in-powershell-ftp/</link>
		<comments>http://feelingsofwhite.com/2007/03/look-what-you-can-do-in-powershell-ftp/#comments</comments>
		<pubDate>Wed, 14 Mar 2007 22:07:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[ftp]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/03/14/look-what-you-can-do-in-powershell-ftp/</guid>
		<description><![CDATA[Imagine my surprise when my friendly neighbourhood I.T. fellow told me a ftp command line client built into windows. Man, I haven't done command line FTP since high school. But after finding a good ftp command reference, well, of course, I couldn't resist trying to concoct an unholy marriage between ftp and powershell.

$listOfFiles = "open [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine my surprise when my friendly neighbourhood I.T. fellow told me a ftp command line client built into windows. Man, I haven't done command line FTP since high school. But after finding a <a href="http://www.nsftools.com/tips/MSFTP.htm">good ftp command reference</a>, well, of course, I couldn't resist trying to concoct an unholy marriage between ftp and powershell.</p>
<p><code><br />
$listOfFiles = "open <span style="font-style:italic;">secret.ftplocation.com</span><br />
user <span style="font-style:italic;">username password</span><br />
binary<br />
cd <span style="font-style:italic;">LocationICareAbout</span><br />
mdir * -" | ftp -i -n | where {$_.Trim() -ne "" } | where {$_.SubString(24,5) -ne "&lt;DIR&gt;"} | %{ $_.SubString(39) }<br />
</code></p>
<p>To explain: FTP can accepted piped-input, but I realized instead of having to put my answerfile into an actual file, I could just use powershell's ability to have multi-line strings and variables pumped right in.</p>
<p>The above text is logging into the ftp location client of yer choice and getting a file listing (the <font face="courier">msdir</font> bit). As I only cared about files, I ignore the "&lt;DIR&gt;"s, and with a bit of basic string manipulation, <span style="font-style:italic;">viola!</span> I've got a list of all files in a given directory</p>
<p><code><br />
$cmd = "open <span style="font-style:italic;">secret.ftplocation.com</span><br />
user <span style="font-style:italic;">username password</span><br />
binary<br />
cd <span style="font-style:italic;">LocationICareAbout</span><br />
" +<br />
($listOfFiles | %{ "get ""$_""`n" })</p>
<p>$cmd | ftp -i -n<br />
</code></p>
<p>To explain: This final bit turns the list of files into another literal string, which says<br />
&nbsp;&nbsp; get FileX<br />
&nbsp;&nbsp; get FileY<br />
etc, which gets piped to <font face="courier">ftp</font>. the end result is a download of all the files in the directory to my hard drive. Of course, you could get creative and do all sorts of manipulations to <font face="courier">$listOfFiles</font>, if that's what turns you on.</p>
<p>I've got another nearly identical script where instead of "get" I say "delete", same concepts. And got another one that builds up <font face="courier">$listOfFiles</font> from a local directory (via <font face="courier">ls</font>) and uses "put" to upload all files from a local dir to the remote dir. You get the idea.</p>
<p><font face="courier">ftp</font> supposedly supports a <font face="courier">-s:filename</font> but I couldn't get it to work. And really, who would want to? Inlining the ftp commands is just so damn sexy!</p>
<p>After Thoughts:<br />
(wherein I blather on and on and get less technical)</p>
<p>Man I had a blast doing this. Within about two hours I'd gone from ftp n00b to having working scripts that actually helped me do my job much faster. I'd been using my <a href="http://www.download.com/3000-2356-10122208.html">favorite abadonware ftp gui</a> to do uploads/downloads and now I had scripts that did it all faster and consistently. </p>
<p>A nice bite-sized problem involving unknown, but good, tools combined with the joy of the admin development model meant figuring it all out was fun for me. The scripts are pretty basic, really, but figuring junk out makes me go a big rubbery one :P</p>
<p>Really, it's that lovely <a href="http://blogs.msdn.com/powershell/archive/2007/01/01/the-admin-development-model-and-send-snippet.aspx">admin development model</a> more than anything else I think I love. (I've done lots of it over my life, but only ever heard the phrase thanks to powershell blogs.) I have built up so many extrodinarily useful scripts over the last few months, by typing commands into a stupid blue window until they worked, then pasting them into notepad and saving it.</p>
<p>Within another month or two I'll have fully automated processes at my job that used to take up days and days and days of peoples times. Of course, it would only take 1 or 2 weeks of dedicated time to do it all, but we all know how that goes.. no one's going to give you official time to fix anything, not that you've got time when everything needs to be done yesterday, so you gotta slip it under the wire. But then! To the rescue! Comes that lovely admin development model (some people might call it agile development too), where I don't have to do it all at once. I just have to add a few more lines to my powershell scripts here and there, and one day *poof* the entire process is a repeatable automated one-liner instead of a clusterfuck of a timewasting error prone inconsistent undocumented manual process.</p>
<p>All part of my grand plan for world domination. One dirty hack at a time.</p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/03/look-what-you-can-do-in-powershell-ftp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>&quot;*.*&quot; -ne &quot;*&quot; (or, old dos habits die hard)</title>
		<link>http://feelingsofwhite.com/2007/02/ne-or-old-dos-habits-die-hard/</link>
		<comments>http://feelingsofwhite.com/2007/02/ne-or-old-dos-habits-die-hard/#comments</comments>
		<pubDate>Mon, 12 Feb 2007 23:28:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/02/12/ne-or-old-dos-habits-die-hard/</guid>
		<description><![CDATA[#  Setup Demonstration Files - Erase Existing Files
    rd -recurse -force c:\LogFiles
    rd -recurse -force c:\Drawings 
# Setup Demonstration Files
    md c:\LogFiles
    echo foo &#124; out-file c:\LogFiles\foo.txt
    md C:\LogFiles\SubDir
    cp c:\LogFiles\foo.txt c:\LogFiles\SubDir
    md [...]]]></description>
			<content:encoded><![CDATA[<p>#  Setup Demonstration Files - Erase Existing Files<br />
<span style="font-family:courier new;">    rd -recurse -force c:\LogFiles</span><br />
<span style="font-family:courier new;">    rd -recurse -force c:\Drawings </span><br />
# Setup Demonstration Files<br />
<span style="font-family:courier new;">    md c:\LogFiles</span><br />
<span style="font-family:courier new;">    echo foo | out-file c:\LogFiles\foo.txt</span><br />
<span style="font-family:courier new;">    md C:\LogFiles\SubDir</span><br />
<span style="font-family:courier new;">    cp c:\LogFiles\foo.txt c:\LogFiles\SubDir</span><br />
<span style="font-family:courier new;">    md c:\Drawings</span><br />
# Does not work as expected<br />
<span style="font-family:courier new;">    cp -recurse -force c:\LogFiles\*.* c:\Drawings  #only copies foo.txt</span><br />
# Does what you want it to<br />
<span style="font-family:courier new;">    cp -recurse -force c:\LogFiles\* c:\Drawings    #copies SubDir + contents</span></p>
<p>Damn, old dos habits die hard.  In fact, it makes perfect sense ("SubDir" does not contain a ".", if it did it would be copied).  But still, I wish someone else had spent that hour or two debuging the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/02/ne-or-old-dos-habits-die-hard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Good Goddamn, Powershell Sucks!</title>
		<link>http://feelingsofwhite.com/2007/02/good-goddamn-powershell-sucks/</link>
		<comments>http://feelingsofwhite.com/2007/02/good-goddamn-powershell-sucks/#comments</comments>
		<pubDate>Tue, 06 Feb 2007 15:46:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/02/06/good-goddamn-powershell-sucks/</guid>
		<description><![CDATA[Apparently Blogger sucks too, 'cause I can't get this picture to display at full resolution. You'll have to click to read it: 
In case you can't be bothered, powershell's remove-item crashes with
"The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory [...]]]></description>
			<content:encoded><![CDATA[<p>Apparently Blogger sucks too, 'cause I can't get this picture to display at full resolution. You'll have to click to read it: <br /><a href="http://bp0.blogger.com/_mingpt0NCso/RcijpUs5ESI/AAAAAAAAAAw/wrP3-z2Ozqg/s1600-h/PowerShellSucks-LongFileNames.PNG"><img style="cursor:pointer;" src="http://bp0.blogger.com/_mingpt0NCso/RcijpUs5ESI/AAAAAAAAAAw/wrP3-z2Ozqg/s400/PowerShellSucks-LongFileNames.PNG" alt="" border="0" /></a></p>
<p>In case you can't be bothered, powershell's remove-item crashes with<br />
"The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."<br />
Then cmd.exe's rd /s /q works just fine. <span style="font-style:italic;">cmd.exe</span>.</p>
<p>Seriously. How. The. Fuck. Does this ship? How the <span style="font-style:italic;">fuck</span> am I unable to delete files that the Operating System will allow me to create? When cmd.exe <span style="font-style:italic;">works</span>? I'm sure there's a really interesting reason why this error happens. Some bizarre technical reason, or, more likely, some political tale about how people wanted to fix it, and couldn't. You know, the type of stuff that makes <a href="http://thedailywtf.com">the daily wtf</a> a popular site. But I don't care. Not right now.</p>
<p>Right now, I want Powershell to work at least as good as what it desires to replace.</p>
<p>I'm thinking there's a solution involving <span style="font-family:courier new;">set-alias rm</span>, but I haven't coded it yet... (probably won't either)</p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/02/good-goddamn-powershell-sucks/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Look what you can do in PowerShell</title>
		<link>http://feelingsofwhite.com/2007/01/look-what-you-can-do-in-powershell/</link>
		<comments>http://feelingsofwhite.com/2007/01/look-what-you-can-do-in-powershell/#comments</comments>
		<pubDate>Thu, 18 Jan 2007 05:03:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[testpoint]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/01/18/look-what-you-can-do-in-powershell/</guid>
		<description><![CDATA[Launch hidden IE windows, invoke an exe and wait for completion, download RSS Feeds and web contents, upload to flickr, invoke script blocks from C#.  OMG I'll faint at all the cool things you can do]]></description>
			<content:encoded><![CDATA[<p>Launching a (potentially hidden) internet explorer application <small>(thanks <a href="http://abhishek225.spaces.live.com/Blog/cns%2113469C7B7CE6E911%21165.entry">Abhishek</a>)</small></p>
<p class="legioncodesnip" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">$a = new-object -com InternetExplorer.Application    <br />$a.visible=$true     <br />$a.Navigate2(&quot;http://www.microsoft.com&quot;)</p>
<p>What's the equivalent to <span style="font-family: courier new">cmd.exe</span>'s <span style="font-family: courier new">start /wait</span> command <small>(thanks <a href="http://thepowershellguy.com/blogs/posh/archive/2007/01/16/powershell-the-admin-development-model.aspx">PowerShell Guy</a>)</small></p>
<p class="legioncode" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">$notepad = [System.Diagnostics.Process]::Start( &quot;notepad.exe&quot; )    <br />$notepad.WaitForExit(2000) #wait 2 seconds     <br />$notepad.WaitForExit() #wait forever     <br /># Note: <a href="http://www.codeplex.com/PowerShellCX/Wiki/View.aspx?title=PSCX%20Features">CodePlex has a Start-Process</a> cmdlet that looks promising </p>
<p><span id="more-90"></span></p>
<p>Retrieving Version Numbers from DLLs and EXEs <small>(thanks <a href="http://jtruher.spaces.live.com/Blog/cns%217143DA6E51A2628D%21125.entry">Time is an illusion</a>)</small></p>
<p class="legioncodesnip" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">ls c:\windows\*.exe | get-fileversion</p>
<p>Download from an RSS Feed <small>(thanks <a href="http://abhishek225.spaces.live.com/Blog/cns%2113469C7B7CE6E911%21134.entry">Abhishek</a>)</small></p>
<p class="legioncode" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">#Create the Service Endpoint Url    <br />$url=(&quot;http://xml.weather.yahoo.com/forecastrss?p=&quot; + &quot;90210&quot;)     <br />#download the rss feed and cast to xml     <br />$webclient = new-object System.Net.WebClient     <br />$weatherData=[xml]$webclient.DownloadString($url)     <br />echo $weatherData.rss.Channel.item.Title</p>
<p>Or just download a website contents</p>
<p class="legioncodesnip">$webclient = new-object System.Net.WebClient    <br />$webclient.DownloadString(&#8221;http://server/location&#8221;)</p>
<p>Someone figured out how to <a href="http://abhishek225.spaces.live.com/Blog/cns%2113469C7B7CE6E911%21285.entry">upload files to fickr</a> via PowerShell. Haha! Neat!</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2006/04/25/583250.aspx">Invoking Script Blocks from C#</a> looks simple&#8230; as long as you know how. <small>(thanks <a href="http://blogs.msdn.com/powershell/archive/2006/04/25/583250.aspx">Windows PowerShell</a>)</small></p>
<p>try <a href="http://www.codeplex.com/PowerShellCX/Project/FileDownload.aspx?DownloadId=4583">Installing CodePlex</a> for things lots of <a href="http://www.codeplex.com/PowerShellCX/Wiki/View.aspx?title=PSCX%20Features">useful new commands</a>. Some of them, like Set-FileDate (touch), Out-Clipboard and Test-Xml should just get bundled in by default.</p>
<p>You can <a href="http://www.sapienpress.com/powershell.pdf">trap and re-throw exceptions</a>. The documentation seems non-existant, but someone was kind enough to release a chapter of their book for free. <small>(Thanks <a href="http://blogs.msdn.com/powershell/archive/2006/12/29/documenting-trap-and-throw.aspx">Windows PowerShell</a>)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/01/look-what-you-can-do-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My First PowerShell</title>
		<link>http://feelingsofwhite.com/2007/01/my-first-powershell/</link>
		<comments>http://feelingsofwhite.com/2007/01/my-first-powershell/#comments</comments>
		<pubDate>Tue, 16 Jan 2007 01:57:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/01/16/my-first-powershell/</guid>
		<description><![CDATA[The PowerShell team once requested everyone to blog your initial powershell experiences, and after a personal appeal, how can I refuse!]]></description>
			<content:encoded><![CDATA[<p>The PowerShell team once requested everyone to <a href="http://blogs.msdn.com/powershell/archive/2007/01/06/blog-your-initial-powershell-experiences.aspx">blog your initial powershell experiences</a>, and after a <a href="http://feelingsofwhite.com/2007/01/starting-out-in-powershell/#comment-19">personal appeal</a>, how can I refuse! I thought maybe enough time had passed that they weren't interested. <small>(maybe I'll even get more <a href="http://feelingsofwhite.com/2007/01/powershell-script-to-edit-profile/#comment-18">ego boosting posts</a>. Can I believe stuff like that? I'm new to blogs. But it's a fun thought)</small></p>
</p>
<p><span id="more-89"></span></p>
<p>I was already a big <a href="http://en.wikipedia.org/wiki/Anders_Hejlsberg">.</a>Net fan and had heard (but forgotten) about PowerShell until our IT guy suggested it for a problem I was having. The hype was promising (object manipulation instead of string parsing! egads!). I read lots, the install was simple and I started playing around. After a few days I forced myself to switch my always-on shell window to PowerShell instead of cmd.exe.</p>
<p>The manuals that came were helpful to start, although I learned most of the basics from online articles. I wish a more complete user manual (that had syntax examples of scripts for example) would come by default. It feels like the product shipped without help. <span style="font-style: italic">Although</span>, the <span style="font-family: courier new">get-help</span> command within PowerShell is <span style="font-weight: bold">fantastic</span>. You guys did an <span style="font-style: italic">awesome</span> job with the contents of <span style="font-family: courier new">get-help</span>.</p>
<p>As a asp.net developer I was more interested in the file-manipulation stuff that could help us with out daily build and .net1.1 -&gt; 2.0 migration. Within less then 2 day I switched us from .bat files to .ps1 files, PowerShell was that good. It saved me time and gave me new options almost instantly. It was the reason I first started this blog.</p>
<p>I love that everything is .Net objects, I love the piping of commands ala unix. It's like being able to work with sql-like commands (ie, set operations) but with any .net object -- fantastic! It scaled from quick &amp; dirty admin-style scripts to full programatic logic control features, exceptions.</p>
<p>And so perl like. Ugh. That took me a while to get over. Why is the command &quot;.&quot; instead of a descriptive &quot;include&quot; keyword? to continue the glorious cryptic command-line traditions?</p>
<p>Oh, and the biggest headache I've had thus far? Calling existing command-line tools from powershell. Passing parameters with spaces always seems to break things as PowerShell interprets variables it's way, instead of the way my mental-model expects them too. Which, I guess, is more .bat file like; expecting environment variable-expansion. So, given that you've got a file called listparams.bat:</p>
<p class="legioncodesnip" style="font-family: courier new">echo parameters were %*</p>
<p>and the command</p>
<p class="legioncodesnip" style="font-family: courier new">.\listparams.bat -buildfile:hi.txt</p>
<p>in cmd.exe, it yeilds</p>
<p class="legioncodesnip" style="font-family: courier new">parameters were -buildfile:hi.txt</p>
<p> but in Powershell.exe it yields
</p>
<p class="legioncodesnip" style="font-family: courier new">parameters were -buildfile: hi.txt</p>
<p>notice the space in the output.</p>
<p>These subtle differences are very frustrating. This particular example is painful when using <a href="http://nant.sourceforge.net/">nant</a> and it's <span style="font-family: courier new">-buildfile:</span> parameter.</p>
<p>Overall I like PowerShell though. Fan-frakking-tastic.</p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/01/my-first-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pithy PowerShell</title>
		<link>http://feelingsofwhite.com/2007/01/pithy-powershell/</link>
		<comments>http://feelingsofwhite.com/2007/01/pithy-powershell/#comments</comments>
		<pubDate>Fri, 12 Jan 2007 22:12:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[job]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/01/12/pithy-powershell/</guid>
		<description><![CDATA[Basic file creation, compare directories, launch browsers, grab information from svn and a few more brief scripts]]></description>
			<content:encoded><![CDATA[<p>Here's some powershell examples from the work I've been doing over the last few days at work. Just some simple one-liners I demoed to show the power of powershell to scratch my own personal itches.</p>
<p>Generate list of .wiki files into a directory listing text file</p>
<div class="legioncodesnip" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">&quot;DevPlan&quot;,&quot;GeoWiki&quot; | %{ ls &quot;$_\*.wiki&quot; &gt; ($_ + &quot;List.txt&quot;) } ; ls</div>
<p>BUT. It's better to use sc (set-content) to write non-utf16, so filesize is smaller and controllable and non-binary for svn (thanks <a href="http://ps1.soapyfrog.com/2007/01/09/text-and-path-gotchas/">soapyfrog</a>)</p>
<div class="legioncodesnip" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">&quot;DevPlan&quot;,&quot;GeoWiki&quot; | %{ ls &quot;$_\*.wiki&quot; | set-content ($_ + &quot;List.txt&quot;) } ; ls</div>
<p>Make a variable with files that exist in both the DevPlan and GeoWiki sub-directory</p>
<div class="legioncodesnip" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">$OverlappingFiles = ls &quot;DevPlan\*.wiki&quot; | %{ if (test-path (join-path GeoWiki $_.Name)) { $_ } }</div>
<p>whow, that &quot;if&quot; statement is clunky. it's better to use where to filter out common files</p>
<div class="legioncodesnip" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">$OverlappingFiles2 = $OverlappingFiles | where { !($_.Name -eq &quot;_ContentBaseDefinition.wiki&quot; -or $_.Name -eq &quot;HomePage.wiki&quot;) }</div>
<p>Launch those files as FlexWiki-compatible browser URLs</p>
<div class="legioncodesnip" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">$OverlappingFiles2 | %{ &amp;$iexplore (&quot;http://m93808/Flexwiki/default.aspx/DevPlan/&quot; + $_.Name.Substring(0, $_.Name.Length - 5)) }</div>
<p>Cache applicationLaunch 10 copies of a url, for both for two sub-domains (Fellow T.G.'ers should peep this)</p>
<div class="legioncodesnip" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">&quot;www1&quot;, &quot;www2&quot; | %{$who=$_ ; 1..10 | %{ &amp;$iexplore (&quot;http://&quot; + $who + &quot;.SomeCompany.com/SomeApps&quot;) }}</div>
<p>Determine the svn revision and url of the current directory</p>
<div class="legioncodesnip" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">(svn info | select-string &quot;revision:*&quot;).Line.SubString(10)   <br />$svnUrl = (svn info | select-string &quot;url:*&quot;).Line.SubString(5) ; $svnUrl </div>
<p>Delete any non-svn-controlled Files</p>
<div class="legioncodesnip" style="margin-left: 3em; color: black; font-family: courier; background-color: lightgrey">svn status | select-string &quot;^\?&quot; | foreach { rm -force -recurse $_.Line.SubString(7) }</div>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/01/pithy-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Testing in PowerShell</title>
		<link>http://feelingsofwhite.com/2007/01/unit-testing-in-powershell/</link>
		<comments>http://feelingsofwhite.com/2007/01/unit-testing-in-powershell/#comments</comments>
		<pubDate>Fri, 12 Jan 2007 04:59:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/01/12/unit-testing-in-powershell/</guid>
		<description><![CDATA[Check it out if you're into that sort of thing]]></description>
			<content:encoded><![CDATA[<p>Wow, <a href="http://testfirst.spaces.live.com/blog/">unit testing in powershell</a>. And other <a href="http://testfirst.spaces.live.com/blog/cns%217E0657B7A0134A74%21136.entry">testing ideas</a>. I think it's cool, but I wonder if I'll ever make myself honestly do any unit testing on stuff that always starts out as quick and dirty scripts. Not that I don't think it's cool. Check it out if you're into that sort of thing.</p>
<p><small>(via <a href="http://blogs.msdn.com/powershell/archive/2007/01/09/windows-powershell-for-testers.aspx">Windows PowerShell</a>)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/01/unit-testing-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell Invaders</title>
		<link>http://feelingsofwhite.com/2007/01/powershell-invaders/</link>
		<comments>http://feelingsofwhite.com/2007/01/powershell-invaders/#comments</comments>
		<pubDate>Mon, 08 Jan 2007 21:42:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[game]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/01/08/powershell-invaders/</guid>
		<description><![CDATA[Some crazy tallented fellow renade space invaders.  In powershell.]]></description>
			<content:encoded><![CDATA[<p><a href="http://ps1.soapyfrog.com/2007/01/02/space-invaders/"><img style="float: right; margin: 0px 0px 10px 10px" height="258" alt="Space Invaders, done in Powershell script" src="http://feelingsofwhite.com/wp-content/uploads/2008/05/powershellinvaders.png" width="320" border="0" /></a> Writing <a href="http://ps1.soapyfrog.com/2007/01/02/space-invaders/">Space Invaders in Powershell</a> is so impressive, and yet so wrong. Although, as someone who once <a href="http://www.analogcoast.com/">co</a>-authored a BBS-system in <a href="http://en.wikipedia.org/wiki/4DOS">4dos</a> batch files, I love it.</p>
<p><small>(via <a href="http://thepowershellguy.com/blogs/posh/archive/2007/01/02/powershell-space-invaders.aspx">The Powershell Guy</a>)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/01/powershell-invaders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Starting out in powershell</title>
		<link>http://feelingsofwhite.com/2007/01/starting-out-in-powershell/</link>
		<comments>http://feelingsofwhite.com/2007/01/starting-out-in-powershell/#comments</comments>
		<pubDate>Sat, 06 Jan 2007 06:57:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[powershell]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[mlp]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/01/06/starting-out-in-powershell/</guid>
		<description><![CDATA[Links to various quick references, blogs and helpfile sites I've found for powershell]]></description>
			<content:encoded><![CDATA[<p>Link to <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx">Install Powershell</a>.</p>
<p>Printable documentation is really sparse (it includes a quickstart guide and a &quot;user guide&quot;, which is missing lots of stuff), but the documentation <span style="font-style: italic">within</span> the powershell on individual commands is really very very good. I listed the powershell blogs I subscribing to below.. I've found them helpful at times, but it's kinda hit-or-miss. The biggest problem I've had is just discovering the basics of how to do things (how do I define a function, how do I make a .ps1 file that accepts parameters (param statement, just like in functions)). But it's totally worth it. Powershell roxors!</p>
<p>Good web pages:</p>
<ul>
<li><a href="http://www.windowsdevcenter.com/pub/a/windows/2006/11/07/top-10-tips-for-using-windows-powershell.html?page=1">good first read</a> </li>
<li><a href="http://channel9.msdn.com/wiki/default.aspx/Channel9.WindowsPowerShellQuickStart">awesome quick reference</a> </li>
<li><a href="http://del.icio.us/jameslikesbeer/powershell">A few more powershell webpages I've tagged</a> </li>
<li><a href="http://www.microsoft.com/technet/scriptcenter/scripts/msh/default.mspx?mfr=true">Script repository that's in its infancy, I haven't used it, but sysadmin/it types might find interesting</a>      </li>
</ul>
<p>Official Blog RSS link</p>
<ul>
<li>http://blogs.msdn.com/powershell/rss.xml</li>
</ul>
<p>Other Blogs RSS links I'm using right now:</p>
<ul>
<li>http://jtruher.spaces.live.com/feed.rss </li>
<li>http://mybsinfo.blogspot.com/feeds/posts/default </li>
<li>http://abhishek225.spaces.live.com/feed.rss </li>
<li>http://monadblog.blogspot.com/feeds/posts/default     </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/01/starting-out-in-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>copycon powershell command</title>
		<link>http://feelingsofwhite.com/2007/01/copycon-powershell-command/</link>
		<comments>http://feelingsofwhite.com/2007/01/copycon-powershell-command/#comments</comments>
		<pubDate>Fri, 05 Jan 2007 21:12:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[technical]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/01/05/copycon-powershell-command/</guid>
		<description><![CDATA[Easily create new files from within the shell.  If you're used to typing "copy con newfile.txt" in dos, this powershell snippet is for you.]]></description>
			<content:encoded><![CDATA[<p>FYI: I didn't create this, I found it on the web (I did add the -encoding bit). But it's so damn useful I've got to post it (if you're an old dos guy used to typing <span style="font-family: courier new">copy con newfile.txt</span> and the like)</p>
<pre class="legioncode">Function CopyfromConsole {
   param ($outfile = &quot;&quot;)

   # encoding is set to ascii because if we leave it at the default
   #  (unicode), svn treats it as a binary file, which is
   # inconvienent for me personally, so old skewl ascii it is

   if ($outfile -eq &quot;&quot;)
   {
      # out-file will prompt user for filename if we don't specify one
      [system.console]::in.readtoend() | out-file -encoding ascii
   }
   Else
   {
      [system.console]::in.readtoend() | out-file $outfile -encoding ascii
   }
}
set-alias copycon CopyfromConsole</pre>
<p>So now just type <span style="font-family: courier new">copycon NewFile.txt</span>, and it's easy for me to create a file</p>
<p><b>update</b>: credit where credit is do, I found the <a href="http://tfl09.blogspot.com/2005/10/monad-and-command-console.html">blog entry</a> this originated from, so thanks to Thomas Lee</p>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/01/copycon-powershell-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>powershell script to edit profile</title>
		<link>http://feelingsofwhite.com/2007/01/powershell-script-to-edit-profile/</link>
		<comments>http://feelingsofwhite.com/2007/01/powershell-script-to-edit-profile/#comments</comments>
		<pubDate>Fri, 05 Jan 2007 21:04:00 +0000</pubDate>
		<dc:creator>Legion</dc:creator>
				<category><![CDATA[technical]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://feelingsofwhite.wordpress.com/2007/01/05/powershell-script-to-edit-profile/</guid>
		<description><![CDATA[A powershell script that invokes an editor on $profile, and re-starts your session if any changes are made]]></description>
			<content:encoded><![CDATA[<p>For the record, I've been playing with powershell for about a week now, and I fucking love it. </p>
<p>Check out my latest function, I am so awesome. </p>
<p>Useful for adding to your profile </p>
<p>(if you haven't rtfm'd, then: new-item $profile -itemType file; notepad $profile. The rest is up to you) </p>
<p>Anyway, it brings up my favorite editor (notepad2), and re-starts powershell (using a path to my own local shortcut) but -- and here's the cool bit -- only if you actually changed your profile</p>
<pre class="legioncode" style="color: black; background-color: lightgrey"># Launches an editor for this file, and re-starts
# powershell if changes were made
function pro {
    #make a backup file
    cp $profile ($profile + &quot;.bak&quot;)

    # piping (non-existant) output makes script wait for exit
    &amp;&quot;c:\Program Files\notepad2\Notepad2.exe&quot; $profile | out-null

    # If user made changes, re-launch shell.  otherwise do nothing
    $old = get-content $profile
    $new = get-content ($profile + &quot;.bak&quot;)
    if ($null -ne (
            Compare-Object -ReferenceObject $new -differenceobject $old
                  )
       ) {

        rm ($profile + &quot;.bak&quot;)

        # user exited editor, re-start powershell
        &amp;&quot;C:\Documents and Settings\All Users\Start Menu\Windows PowerShell.lnk&quot;

        # quit this particular shell
        exit
    }
    rm ($profile + &quot;.bak&quot;)
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://feelingsofwhite.com/2007/01/powershell-script-to-edit-profile/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
