@@ -422,7 +422,7 @@ parses foo but leaves "--bar" in $(D args). The double-dash itself is
422
422
removed from the argument array unless the $(D std.getopt.config.keepEndOfOptions)
423
423
directive is given.
424
424
*/
425
- GetoptResult getopt (T... )(ref string [] args, T opts)
425
+ GetoptResult getopt (T... )(ref string [] args, scope T opts)
426
426
{
427
427
import std.exception : enforce;
428
428
enforce(args.length,
@@ -459,6 +459,19 @@ GetoptResult getopt(T...)(ref string[] args, T opts)
459
459
}
460
460
}
461
461
462
+ version (DIP1000)
463
+ {
464
+ @safe unittest
465
+ {
466
+ auto args = [" prog" , " --foo" , " -b" ];
467
+
468
+ bool foo;
469
+ bool bar;
470
+ auto rslt = getopt(args, " foo|f" , " Some information about foo." , &foo, " bar|b" ,
471
+ " Some help message about bar." , &bar);
472
+ }
473
+ }
474
+
462
475
/**
463
476
Configuration options for $(D getopt).
464
477
@@ -681,7 +694,7 @@ private template optionValidator(A...)
681
694
682
695
private void getoptImpl (T... )(ref string [] args, ref configuration cfg,
683
696
ref GetoptResult rslt, ref GetOptException excep,
684
- void [][string ] visitedLongOpts, void [][string ] visitedShortOpts, T opts)
697
+ void [][string ] visitedLongOpts, void [][string ] visitedShortOpts, scope T opts)
685
698
{
686
699
enum validationMessage = optionValidator! T;
687
700
static assert (validationMessage == " " , validationMessage);
@@ -700,7 +713,16 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
700
713
else
701
714
{
702
715
// it's an option string
703
- auto option = to! string (opts[0 ]);
716
+ static if (is (typeof (opts[0 ]) == string ))
717
+ {
718
+ // allocate a new string so as to remove the
719
+ // scope restriction
720
+ string option = " " ~ opts[0 ];
721
+ }
722
+ else
723
+ {
724
+ string option = to! string (opts[0 ]);
725
+ }
704
726
if (option.length == 0 )
705
727
{
706
728
excep = new GetOptException(" An option name may not be an empty string" , excep);
@@ -729,7 +751,9 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
729
751
static if (is (typeof (opts[1 ]) : string ))
730
752
{
731
753
auto receiver = opts[2 ];
732
- optionHelp.help = opts[1 ];
754
+ // allocate a new string so as to remove the
755
+ // scope restriction
756
+ optionHelp.help = " " ~ opts[1 ];
733
757
immutable lowSliceIdx = 3 ;
734
758
}
735
759
else
@@ -802,7 +826,7 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
802
826
}
803
827
}
804
828
805
- private bool handleOption (R)(string option, R receiver, ref string [] args,
829
+ private bool handleOption (R)(string option, scope R receiver, ref string [] args,
806
830
ref configuration cfg, bool incremental)
807
831
{
808
832
import std.algorithm.iteration : map, splitter;
0 commit comments