@@ -56,8 +56,8 @@ private ExportableOptionCollection BuildOptionSet(List<ParsedOp> parsed, List<st
56
56
"{encrypted} {clear}:Decrypt a file to the given file path." ,
57
57
( ora , op , from , to ) => ora . Add ( op , from , to ) } ,
58
58
{ "e|encrypt-to={}" , XfOpCode . EncryptTo ,
59
- "{clear} {encrypted}:Encrypt a file to the given file path." ,
60
- ( ora , op , from , to ) => ora . Add ( op , from , to ) } ,
59
+ "{clear} {encrypted} [{original}] :Encrypt a file to given file path w/optional original name ." ,
60
+ ( ora , op , from , to ) => ora . AddOneRunning ( op , from , to ) } ,
61
61
{ "f|file=" , XfOpCode . OptionsFromFile ,
62
62
"{name}:Take options from a file (programmatic)." ,
63
63
( ora , op , name ) => { ora . Add ( op ) ; RecursivelyParseFromFile ( name , parsed , extra ) ; } } ,
@@ -276,13 +276,26 @@ public void Add(XfOpCode opCode, string p1, string p2)
276
276
RunningAction = _noop ;
277
277
}
278
278
279
+ public void Add ( XfOpCode opCode , string p1 , string p2 , string p3 )
280
+ {
281
+ _parsed . Add ( new ParsedOp ( opCode , p1 , p2 , p3 ) ) ;
282
+ RunningAction = _noop ;
283
+ }
284
+
279
285
public void AddOneRunning ( XfOpCode opCode , string first )
280
286
{
281
287
var op = new ParsedOp ( opCode , first ) ;
282
288
_parsed . Add ( op ) ;
283
289
RunningAction = ( s ) => { op . Arguments . Add ( s ) ; RunningAction = _noop ; } ;
284
290
}
285
291
292
+ public void AddOneRunning ( XfOpCode opCode , string first , string second )
293
+ {
294
+ ParsedOp op = new ( opCode , first , second ) ;
295
+ _parsed . Add ( op ) ;
296
+ RunningAction = ( s ) => { op . Arguments . Add ( s ) ; RunningAction = _noop ; } ;
297
+ }
298
+
286
299
public void AddManyRunning ( XfOpCode opCode , string first )
287
300
{
288
301
var op = new ParsedOp ( opCode , first ) ;
@@ -291,6 +304,17 @@ public void AddManyRunning(XfOpCode opCode, string first)
291
304
}
292
305
}
293
306
307
+ private sealed class MyActionOption ( string prototype , string description , int count ,
308
+ Action < OptionValueCollection > action ) : OptionBase ( prototype , description , count )
309
+ {
310
+ protected override void OnParseComplete ( OptionContext c )
311
+ {
312
+ ArgumentNullException . ThrowIfNull ( c ) ;
313
+
314
+ action ( c . OptionValues ) ;
315
+ }
316
+ }
317
+
294
318
private class ExportableOptionCollection ( Version cliVersion , RunningArguments ora ) : OptionSetCollection
295
319
{
296
320
/// <summary>
@@ -331,6 +355,21 @@ public void Add(string prototype, XfOpCode opCode, string description, Action<Ru
331
355
_ = Add ( prototype , description , ( p1 , p2 ) => action ( ora , opCode , p1 , p2 ) ) ;
332
356
Export . Add ( new ExportableOption ( ( int ) opCode , prototype , string . Join ( ':' , ( description ? . Split ( ':' ) . Skip ( 1 ) . ToArray ( ) ?? [ ] ) ) ) ) ;
333
357
}
358
+
359
+ public void Add ( string prototype , string description , Action < string , string , string > action )
360
+ {
361
+ ArgumentNullException . ThrowIfNull ( action ) ;
362
+
363
+ OptionBase p = new MyActionOption ( prototype , description , 3 ,
364
+ delegate ( OptionValueCollection v ) { action ( v [ 0 ] , v [ 1 ] , v [ 2 ] ) ; } ) ;
365
+ Add ( p ) ;
366
+ }
367
+
368
+ public void Add ( string prototype , XfOpCode opCode , string description , Action < RunningArguments , XfOpCode , string , string , string > action )
369
+ {
370
+ Add ( prototype , description , ( p1 , p2 , p3 ) => action ( ora , opCode , p1 , p2 , p3 ) ) ;
371
+ Export . Add ( new ExportableOption ( ( int ) opCode , prototype , string . Join ( ':' , ( description ? . Split ( ':' ) . Skip ( 1 ) . ToArray ( ) ?? [ ] ) ) ) ) ;
372
+ }
334
373
}
335
374
336
375
private void RecursivleyParseArguments ( IEnumerable < string > args , List < ParsedOp > parsedOps , List < string > extra )
0 commit comments