 |
|
 |
Hi,
Thank you for finding this complete ripoff.
I'm not even angry, I'm really sorry for the guy. He even put a copyright in it indeed and moreover a more restrictive GPL license. Also it says created in "March 2008".
So I am going to warn the guy and notify the website to remove the article.
Thank you again very much,
R. LOPES
Just programmer.
Http://sili.co.nz/blog
|
|
|
|
 |
|
 |
I am about to create our command line version for ES2009 and went looking for a sample. I found yours, went to look at a few more articles, found his and was like what the heck? By the way, ES2009 runs under Visual Studio and doesn't require MyGeneration or CodeSmith anymore (sorry for the commerical). I really thought in the end his article was yours since the names seemed to almost match.
- Mike
|
|
|
|
 |
|
 |
Hi,
Is there already a trial for ES2009 ?
I forget to look even if I just finished reading the ES2009 features and some of your blog posts. I saw there was one trial for ES2008 but this one still rely on MyGeneration. Actually MyGeneration is great, I used it for many tasks in the past. Of course for the OR/M, Visual Studio integration is a definitive plus.
By the way I responded to the guy that ripped off my article, and I posted that: http://sili.co.nz/blog/2009/01/hello-you-have-been-ripped-off/
Thanks again,
R. LOPES
Just programmer.
Http://sili.co.nz/blog
|
|
|
|
 |
|
 |
I found that on XP the inclusion of double quotes "" would cause separate command line options to be merged into a single command line argument passed into Main.
For example:
myapp.exe /dir:"C:\program files\myapp\data" /confirm:true /server:localhost
on XP void Main(string[] args) would contain only two arguments.
args[0] myapp.exe
args[1] /dir:"C:\program files\myapp\data" /confirm:true /server:localhost
The only way to make it work on XP was to replace the double quotes with single quotes
myapp.exe /dir:'C:\program files\myapp\data' /confirm:true /server:localhost
which would then correclty return
args[0] myapp.exe
args[1] /dir:'C:\program files\myapp\data'
args[2] /confirm:true /server:localhost
args[3] /server:localhost
Todd Smith
|
|
|
|
 |
|
 |
NConsoler is an open source library that provides command line parser functionality based on attribute metadata attached to type.
Library is very easy to add and use in your application. NConsoler gives an ability to display help and validation messages without any line of code.
http://nconsoler.csharpus.com/
Example code:
using System;
using NConsoler;
public class Program {
public static void Main(params string[] args) {
Consolery.Run(typeof(Program), args);
}
[Action]
public static void Method(
[Required] string name,
[Optional(true)] bool flag) {
Console.WriteLine("name: {0}, flag: {1}", name, flag);
}
}
and use it:
program.exe "Maxim" /-flag
|
|
|
|
 |
|
 |
Hey, thank you very much!
But I have changed my code to inheritance:
public class Arguments : Dictionary<string,>
Like that I can use all the functionality of a Dictionary class. That makes it much easier. That didn't needed a lot of changes in the using code, but it gives a lot more comfort.
Greets tt
--------------
the whole code:
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace CommandLine.Utility
{
{
public Arguments(string[] Args)
{
Regex splitter = new Regex( @"^-{1,2}|^/|=|:",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
Regex remover = new Regex( @"^['""]?(.*?)['""]?$",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
string parameter = null;
string[] parts;
foreach (string Txt in Args)
{
parts = splitter.Split(Txt, 3);
switch (parts.Length)
{
case 1:
if (parameter != null)
{
if (!base.ContainsKey(parameter))
{
parts[0] = remover.Replace(parts[0], "$1");
base.Add(parameter, parts[0]);
}
parameter = null;
}
break;
case 2:
if (parameter != null)
{
if (!base.ContainsKey(parameter))
{
base.Add(parameter, "true");
}
}
parameter = parts[1];
break;
case 3:
if (parameter != null)
{
if (!base.ContainsKey(parameter))
base.Add(parameter, "true");
}
parameter = parts[1];
if (!base.ContainsKey(parameter))
{
parts[2] = remover.Replace(parts[2], "$1");
base.Add(parameter, parts[2]);
}
parameter = null;
break;
}
}
if (parameter != null)
{
if (!base.ContainsKey(parameter))
{
base.Add(parameter, "true");
}
}
}
}
}
|
|
|
|
 |
|
 |
Great peace of code.
What about adding a prop Count, so we can check in our apps
Arguments CommandLine = new Arguments(args);
if (CommandLine.Count > 0)
// do parm proccessing
else
Console.WriteLine("No Parms Defined");
TNX!
modified on Friday, May 16, 2008 5:31 AM
|
|
|
|
 |
|
 |
Hi,
I wanted to use your code in my application and I wanted to know what are the restrictions on the usage. Please let me know the type of license you have attached to this code.
Thank you
|
|
|
|
 |
|
 |
Any mention of the license type? I'm finding this handy too and want to use it in a small tool im writing.
Thanks
|
|
|
|
 |
|
 |
Hi there,
Thank you.
The license is: "free to use and to modify". I don't any license on these piece of code. If you want to, you can mention me .
All my new stuff use MIT license and is this also very permissive even for commercial applications.
Cheers,
Richard LOPES
Just programmer.
|
|
|
|
 |
|
 |
I tried the suggestion to remove |: from the Splitter regex and it does fix file name issue but now it can not read value of height defined as /height:'400' on the command line.
Also someone else suggested to make change in the regex. I can't find the original statement in the code, nor does the mod work.
Any help is much appreciated.
|
|
|
|
 |
|
 |
Very powerful and easy to use.
Never trust a computer you can't throw out a window.
|
|
|
|
 |
|
 |
Saved me hours of work and it works first go.
Have done this before many times in the old UNIX days
and didn't really want to go through it all again.
Thanks.
|
|
|
|
 |
|
 |
I am new to C# (old time C coder) and remember what a pain it was to parse args[]... this was a 10 minute setup (I had to figure out how to use "Project...Add existing item..." to add the .cs file to my project and w/o any code changes it just worked exactly how I needed it to.
Thanks!
|
|
|
|
 |
|
 |
This is a great little piece of code. Thumbs up for that.
It's also a beautiful illustration of the reputation of "the French way of doing things".
In the Netherlands we have a proverb about this.
I just hope people interested in this code have the time to go through all the comments, because without them, you might lose a lot of time debugging.
We also have a saying "Live like God in France", so it must be an enjoyable country to live in. Or at least at some point in time.
|
|
|
|
 |
|
 |
Thanks for the code. I intergrated it with an in-house project in 10 minutes.
I had to make the change to handle filename paths (Im need; -output c:\temp\foo.html, quickly fixed by removing |: from regex as posted below).
Nice one!
|
|
|
|
 |
|
 |
Thanks for the code example, GriffonRL. I used your class to quickly put together a parser for my program, defiantly less of a hassle then putting it together myself.
I'm not complaining, but just saying, because you look like your taking advice for the next version, the resulting calls to the object getting alittle messy with all the if else statements. Maybe it could be handled better on my end. It would also be cool to make the parser recognize two unique commands as being the same, like -h and -?, for example.
Anyway, thanks alot for the code, defiantly made my day easier, if I give any serious thought to improvements I'll post something more indepth.
|
|
|
|
 |
|
 |
The class seems to be broken when trying to use space separated name/value pairs. For example, a parameter such as:
-xmlFile="E:\HOME PWR Reports\MembershipRpt.xml"
returns a value of "true" for 'xmlFile'.
|
|
|
|
 |
|
 |
Hi,
Strange, the class is build to handle this kind of scenario. It works for me. You can try to use simple quotes instead of double quotes. Are you also passing other parameters before or after your xmlfile path ? I would like to reproduce the problem.
I may have also to try with the downloadable version on Codeproject because the version I casually use in my apps is an updated one.
Cheers,
R. LOPES
Just programmer.
|
|
|
|
 |
|
 |
Hi,
I didn't tried it yet but you can also tweak the splitter regex and remove the ':' character from it. The other reason could be the space you have in your path even if you enclosed everything inside double quotes. Of course, this should not be a problem unless... Unless you get the parameters from Environment.CommandLine instead of the Args array.
Happy coding,
R. LOPES
Just programmer.
|
|
|
|
 |
|
 |
Try this pls:
Regex isParam = new Regex(@"^^-{1,2}|^/",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
Regex Spliter = new Regex(@"^-{1,2}|^/|=|:",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
[...]
bool isparam = isParam.IsMatch(Txt);
if (isparam)
Parts = Spliter.Split(Txt, 3);
else
Parts = new string[] { Txt };
This will splitt only if - -- oder / detected.
|
|
|
|
 |
|
 |
I really like your command-line parser - alas, it lets me down in one case:
if I have an argument that expects a file name including a path, such as "C:\temp\*.xml", I cannot seem to get those properly.
When I call my app with an argument "/filespec c:\temp\*.xml", or even when I put the file name / path in double quotes ("), I always get "True" for the "filespec" argument.
It appears that the parser will choke on the ":" in the path and think this is another argument to split up; it should *NOT* do this, especially if the file path/file spec is enclosed in double quotes!
Any chance you could fix this? Also- whenever I download your code, I always seem to get the v1.0 version (Oct 2002) - not the bug fixed version of November. Did you upload the most current version at all?
Thanks again for a great little piece of software!
=============================
Marc Scheuner, Berne, Switzerland
mscheuner - at - gmail.com
May The Source Be With You!
|
|
|
|
 |
|
 |
Hi Marc,
Good points.
For your parsing problem, you found a problem. This could be fixed by tweaking the regex in case one use " or ' characters. The splitter regex has to be enhanced for such cases. But I may be not enough. I didn't have the time right now to look at the problem, because of a heavy schedule. If you are really in need you can give it a try.
That leads us to the second good point you made. I didn't updated the source in the past 2 years but I should do it some day because many people in the comments threads came up with good ideas and fixes. Again I am always postponing this task of puting every contributed bit together to upload an updated and rock solid version. However, I think I can manage at last a moment before mid-september to update the code, the article and give credits to every people who pointed out problems, fixes and enhancements. Please note I use an enhanced version of this class myself (but this doesn't include the fix you need).
I'm sorry not to come right now with a good answer. It's at the very least on my todo list.
Keep coding,
R. LOPES
Just programmer.
|
|
|
|
 |
|
 |
Simply removing the "|:" from the regex seems to fix the problem. That is never a legitimate delimiter that I have heard of anyway.
This also solves the problem above which has ":" in the parameter.
Dave
|
|
|
|
 |
|
 |
the "|:" delimiter is most certainly a valid delimiter, but only in one very specific instance is it ever used that I can think of. That instance being the processing of Optical Character Recognition fields when determining the begining of an ABA Routing numbers and Account numbers fields on checks. The "|:" is used to delimit the begining of a new field either the ABA Routing number or the account number example |:123456789|:1112223334444"' 0001 as you can see from this example the aba routing number is preceded and anteceded by the "|:" character and an OCR system is instructed that data to follow represents a contiguous field from that special delimiter. Hopefuly your needs will not include OCR Check Processing but if it does you may need to put that "|:" delimiter back in
HTH
|
|
|
|
 |