Skip to content

Commit b340602

Browse files
whitespaces must be quoted with \"
1 parent b5b5f90 commit b340602

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

UltraMapper.CommandLine.Example/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace UltraMapper.CommandLine.Example
99
class Program
1010
{
1111
static void Main( string[] args )
12-
{
12+
{
1313
//--add ("John Smith" 26 account=( number=AC2903X balance=3500.00 creditcards=[(CRD01 1000.00) (CRD02 2000.00)]))
1414
ConsoleLoop.Start<CustomerCommands>( args );
1515
}
@@ -18,10 +18,9 @@ public class CustomerCommands
1818
{
1919
public void Import( string tipoFlusso, string file )
2020
{
21-
Console.WriteLine(tipoFlusso);
21+
Console.WriteLine( tipoFlusso );
2222
}
2323

24-
2524
[Option( Name = "add", HelpText = "Adds new customer to db" )]
2625
public void AddToDatabase( CustomerInfo customer )
2726
{

UltraMapper.CommandLine/ConsoleLoop.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@ public static void Start<T>( string[] args, T instance,
3131
}
3232
else
3333
{
34-
autoparser.Parse( args, instance );
35-
onParsed?.Invoke( instance );
36-
args = null;
34+
try
35+
{
36+
autoparser.Parse( args, instance );
37+
onParsed?.Invoke( instance );
38+
}
39+
finally
40+
{
41+
args = null;
42+
}
3743
}
3844
}
3945
catch( UndefinedCommandException argumentEx )

UltraMapper.CommandLine/Parsers/DefaultParser.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,31 +122,7 @@ public sealed class DefaultParser : ICommandLineParser
122122

123123
public IEnumerable<ParsedCommand> Parse( string[] args )
124124
{
125-
//Allegedly an array of commands has already been processed and split (and quotes removed)
126-
//by the command line. In theory every item equals a param, so it should be safe to quote
127-
//every single array item containing a whitespace and just rejoin and resplit the array.
128-
//
129-
//Moreover it should be ok in case a single string in the array contains more than one command
130-
//or commands span more than one string.
131-
132-
IEnumerable<string> requote( string[] cmds )
133-
{
134-
foreach( var item in cmds )
135-
{
136-
if( item.Any( c => Char.IsWhiteSpace( c ) ) )
137-
{
138-
if( !item.StartsWith( "\"" ) )
139-
yield return $"\"{item}\"";
140-
}
141-
else
142-
{
143-
yield return item;
144-
}
145-
}
146-
}
147-
148-
var quotedCommands = requote( args );
149-
return this.Parse( String.Join( " ", quotedCommands ) );
125+
return this.Parse( String.Join( " ", args ) );
150126
}
151127

152128
public IEnumerable<ParsedCommand> Parse( string commandLine )

0 commit comments

Comments
 (0)