@@ -517,7 +517,7 @@ class InitCommand : Command {
517
517
free_args = free_args[1 .. $];
518
518
}
519
519
520
- string input (string caption, string default_value)
520
+ static string input (string caption, string default_value)
521
521
{
522
522
writef(" %s [%s]: " , caption, default_value);
523
523
auto inp = readln();
@@ -829,6 +829,7 @@ class GenerateCommand : PackageBuildCommand {
829
829
}
830
830
831
831
class BuildCommand : GenerateCommand {
832
+ bool m_yes; // automatic yes to prompts;
832
833
this ()
833
834
{
834
835
this .name = " build" ;
@@ -848,12 +849,70 @@ class BuildCommand : GenerateCommand {
848
849
args.getopt(" f|force" , &m_force, [
849
850
" Forces a recompilation even if the target is up to date"
850
851
]);
852
+ args.getopt(" y|yes" , &m_yes, [
853
+ ` Automatic yes to prompts. Assume "yes" as answer to all prompts and run non-interactively.`
854
+ ]);
851
855
super .prepare(args);
852
856
m_generator = " build" ;
853
857
}
854
858
855
859
override int execute (Dub dub, string [] free_args, string [] app_args)
856
860
{
861
+ // single package files don't need to be downloaded, they are on the disk.
862
+ if (free_args.length < 1 || m_single)
863
+ return super .execute(dub, free_args, app_args);
864
+
865
+ const package_parts = splitPackageName(free_args[0 ]);
866
+ const package_name = package_parts.name;
867
+
868
+ static bool input (string caption, bool default_value = true ) {
869
+ writef(" %s [%s]: " , caption, default_value ? " Y/n" : " y/N" );
870
+ auto inp = readln();
871
+ string userInput = " y" ;
872
+ if (inp.length > 1 )
873
+ userInput = inp[0 .. $ - 1 ].toLower;
874
+
875
+ switch (userInput) {
876
+ case " no" , " n" , " 0" :
877
+ return false ;
878
+ case " yes" , " y" , " 1" :
879
+ default :
880
+ return true ;
881
+ }
882
+ }
883
+
884
+ Dependency dep;
885
+
886
+ if (package_parts.version_.length > 0 ) {
887
+ // the user provided a version manually
888
+ free_args[0 ] = package_name;
889
+ dep = Dependency(package_parts.version_);
890
+ } else {
891
+ const pack = dub.packageManager.getFirstPackage(package_name);
892
+ if (pack)
893
+ return super .execute(dub, free_args, app_args);
894
+
895
+ // search for the package and filter versions for exact matches
896
+ auto search = dub.searchPackages(package_name)
897
+ .map! (tup => tup[1 ].find! (p => p.name == package_name))
898
+ .filter! (ps => ! ps.empty);
899
+ if (search.empty)
900
+ return 2 ;
901
+
902
+ const p = search.front.front;
903
+ logInfo(" %s wasn't found locally, but it's available online:" , package_name);
904
+ logInfo(" ---" );
905
+ logInfo(" Description: %s" , p.description);
906
+ logInfo(" Version: %s" , p.version_);
907
+ logInfo(" ---" );
908
+
909
+ const answer = m_yes ? true : input(" Do you want to fetch %s?" .format(package_name));
910
+ if (! answer)
911
+ return 0 ;
912
+ dep = Dependency(p.version_);
913
+ }
914
+
915
+ dub.fetch(package_name, dep, dub.defaultPlacementLocation, FetchOptions.none);
857
916
return super .execute(dub, free_args, app_args);
858
917
}
859
918
}
0 commit comments