Monday, 26 January 2009

CommandLine.dll: Previous Releases Fix Published!

The bug found in release 1.5 (see this post) was corrected also in releases already published.
The problem affected:
Latest Release (Version is not afflicted from this problem.
Previous Releases contains now a new download with easy instructions.

Bye and be free to use the version you like!

Sunday, 25 January 2009

CommandLine.dll fix the bug of release 1.5.

If you have read the previous blog post and you're a CommandLine.dll user, please download the latest release: at CodePlex.

If you read the {project-root}/doc/ChangeLog, you will have some more details.

Bye! ;-)

Sunday, 18 January 2009

CommandLine.dll 1.5: sneaky bug introduced in latests version(s) - here the patch!

As soon as possible I will publish the fixed version on CodePlex, for the ones that can't wait follows the patch.
Replace the content of {project-root}/Core/OptionMap.cs with the one here below.

namespace CommandLine
using System.Collections.Generic;

sealed class OptionMap : IOptionMap
private Dictionary<string, string> names;
private Dictionary<string, OptionInfo> map;

public OptionMap(int capacity)
this.names = new Dictionary<string, string>(capacity); = new Dictionary<string, OptionInfo>(capacity * 2);

public OptionInfo this[string key]
OptionInfo option = null;
if (
option =[key];
string optionKey = null;
if (this.names.ContainsKey(key))
optionKey = this.names[key];
option =[optionKey];
return option;
{[key] = value;
if (value.HasBothNames)
this.names[value.LongName] = value.ShortName;

public bool EnforceRules()
foreach (OptionInfo option in
if (option.Required && !option.IsDefined)
return false;
return true;

The bug causes the overloads of bool CommandLineParser.ParseArguments(...) to raise an exception, instead of returning false in case of undefined option.
In the next release I will explain how these kind of thing can happen and how to avoid them.


Thursday, 15 January 2009

Hands on Code: Modify Copy Directory Tree 1.1

The first part of the title states Hands on Code and will prefix every post in which you can find a little tutorial on hacking open source projects.
At the moment of writing this post, cptree, a little utility I wrote for replicate directory tree structures, is marked 1.1 stable. This little command line tool consumes Command Line Parser Library 1.4 stable (from now libcmdline-{VERSION}).
Tutorial Purpose
In this tutorial we will upgrade cptree-1.1 to use libcmdline-1.5. Anyway this time we will remove the binary dependency of CommandLine.dll, merging its code with the source of cptree.exe.
Point your browser to cptree release 1.1 page and download Download also from release 1.5 page of libcmdline.
Unzip cptree source in your project folder. Open the ThisAssembly.cs file located in {cptree-root}/src/Properties.
static class ThisAssembly
internal const string Name = "cptree";
internal const string Title = "cptree.exe";
internal const string Copyright = "Copyright (C) 2008 Giacomo Stelluti Scala";
internal const string Version = ""; //stable
internal const string InformationalVersion = "";
internal const string MajorMinorVersion = "1.1";

The last four fields should be modified as follows.

internal const string Copyright = "Copyright (C) 2008 - 2009 Giacomo Stelluti Scala, {Your-Name}";
internal const string Version = ""; //stable ( tutorial)
internal const string InformationalVersion = "";

Open the CPTreeTool.cs file, located in the project root. Locate the Options nested type and search the following line inside the string GetUsage(void) method.
info.AddPreOptionsLine("  - Uses CommandLine.dll, Version 1.4 (");

Replace this line of code with this other one.
info.AddPreOptionsLine("  - Includes Command Line Library Version 1.5 (");

Now remove the dependency from CommandLine.dll. If you use some version of MS Visual Studio 2008 you're just one click away from the result.

If you use NAnt Build Script you should remove the include tag with the CommandLine.dll string inside the name attribute. This tag is located inside the target tag marked build (attribute name="build").
Now create a CommandLine directory with a Tests subdirectory in the root of cptree. Decompress the in a temporary folder. Move all the *Fixture.cs files to {cptree-root}/src/CommandLine/Tests and the remaining *.cs file to {cptree-root}/src/CommandLine (excluding AssemblyInfo.cs and ThisAssembly.cs).
If you use MS Visual Studio just press the Show All Files button in the project tree, select the CommandLine folder (should be white with dashed border) with the right mouse button and choose Include In Project menu item.
NAnt users have to modify the build scrirpt located in {cptree-root}/nant named If you are familiar with this tool you will not find difficulties including al *.cs file of the new .../CommandLine directory. If you want use the same condition to add .../CommandLine/Tests only if this kind of build is required. (I think it's take more time to explain than modify the script...)
With this little tutorial we have started learning to manage, modify and work with code written by other persons. I think this is one of the basis of open source.

The instructions published here are valid also for different project versions. If you want exercise, you could repeat this tutorial with older versions; for example you could merge cptree-1.0-alfa with libcmdline-1.3-stable. This is valid also for future versions: you'll be able to experiment how the next version of libcmdline will operate (and/or merge) with current (1.1-stable) or older versions of cptree.

For any problem don't esitate to contact me.
Good Job!

Monday, 12 January 2009

Enable syntax highlight in your blog?

There are various solution to add this syntax highlight in posts of your technical blog. The only problem is to choose the right product for your blog engine.

I used syntaxhighlighter from Google Code and this blog post to put it working.


Thursday, 8 January 2009

Command Line Library 1.5 Stable, published!

This new release (1.5 stable) supports enumeration types in native way. You can read more about this the release page, where you can download (as always) source code, binaries and documentation (CHM format).

As older releases sources can be built under Mono (test done under Linux) using NAnt. Published binaries were built using MS Visual C# Express Edition 2008 under a Win32 Platform (you can directly use these files in Mono without rebuilding, if you want...).