@@ -56,8 +56,8 @@ private ExportableOptionCollection BuildOptionSet(List<ParsedOp> parsed, List<st
5656 "{encrypted} {clear}:Decrypt a file to the given file path." ,
5757 ( ora , op , from , to ) => ora . Add ( op , from , to ) } ,
5858 { "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 ) } ,
6161 { "f|file=" , XfOpCode . OptionsFromFile ,
6262 "{name}:Take options from a file (programmatic)." ,
6363 ( ora , op , name ) => { ora . Add ( op ) ; RecursivelyParseFromFile ( name , parsed , extra ) ; } } ,
@@ -276,13 +276,26 @@ public void Add(XfOpCode opCode, string p1, string p2)
276276 RunningAction = _noop ;
277277 }
278278
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+
279285 public void AddOneRunning ( XfOpCode opCode , string first )
280286 {
281287 var op = new ParsedOp ( opCode , first ) ;
282288 _parsed . Add ( op ) ;
283289 RunningAction = ( s ) => { op . Arguments . Add ( s ) ; RunningAction = _noop ; } ;
284290 }
285291
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+
286299 public void AddManyRunning ( XfOpCode opCode , string first )
287300 {
288301 var op = new ParsedOp ( opCode , first ) ;
@@ -291,6 +304,17 @@ public void AddManyRunning(XfOpCode opCode, string first)
291304 }
292305 }
293306
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+
294318 private class ExportableOptionCollection ( Version cliVersion , RunningArguments ora ) : OptionSetCollection
295319 {
296320 /// <summary>
@@ -331,6 +355,21 @@ public void Add(string prototype, XfOpCode opCode, string description, Action<Ru
331355 _ = Add ( prototype , description , ( p1 , p2 ) => action ( ora , opCode , p1 , p2 ) ) ;
332356 Export . Add ( new ExportableOption ( ( int ) opCode , prototype , string . Join ( ':' , ( description ? . Split ( ':' ) . Skip ( 1 ) . ToArray ( ) ?? [ ] ) ) ) ) ;
333357 }
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+ }
334373 }
335374
336375 private void RecursivleyParseArguments ( IEnumerable < string > args , List < ParsedOp > parsedOps , List < string > extra )
0 commit comments