]> git.tdb.fi Git - builder.git/blobdiff - source/buildercli.cpp
Update comments to reflect the new roles of classes
[builder.git] / source / buildercli.cpp
index bcd439e854c6fc9afb05df7832c0e192c3f87845..0bdf8777d0f51cfb5909821d0b119db0ccfc0860 100644 (file)
@@ -63,10 +63,17 @@ BuilderCLI::BuilderCLI(int argc, char **argv):
        getopt.add_option(     "max-depth",  max_depth,     GetOpt::REQUIRED_ARG).set_help("Show up to NUM levels in analysis.", "NUM");
        getopt.add_option(     "prefix",     prefix,        GetOpt::REQUIRED_ARG).set_help("Install things to DIR.", "DIR");
        getopt.add_option(     "tempdir",    tempdir,       GetOpt::REQUIRED_ARG).set_help("Store temporary files in DIR.", "DIR");
-       usagemsg = getopt.generate_usage(argv[0])+" [<target> ...]";
-       helpmsg = getopt.generate_help();
+       getopt.add_argument("target", cmdline_targets, GetOpt::OPTIONAL_ARG).set_help("Target(s) to build");
        getopt(argc, argv);
 
+       if(help)
+       {
+               helpmsg = "Usage:\n  ";
+               helpmsg += getopt.generate_usage(argv[0], true);
+               helpmsg += "\n\n";
+               helpmsg += getopt.generate_help();
+       }
+
        if(silent)
                --verbose;
        if(verbose>=1)
@@ -166,26 +173,20 @@ BuilderCLI::~BuilderCLI()
 int BuilderCLI::main()
 {
        FS::Path main_file = cwd/build_file;
-       if(!FS::exists(main_file))
+       if(FS::exists(main_file))
+               builder.load_build_file(main_file, &cmdline_options, conf_all);
+       else if(!help)
        {
-               if(help)
-               {
-                       usage(0, "builder", false);
-                       return 0;
-               }
-               else
-               {
-                       IO::print(IO::cerr, "The file %s does not exist.\n", main_file);
-                       return 1;
-               }
+               IO::print(IO::cerr, "The file %s does not exist.\n", main_file);
+               return 1;
        }
 
-       builder.load_build_file(main_file, &cmdline_options, conf_all);
-
        if(help)
        {
-               usage(0, "builder", false);
-               IO::print("\n");
+               IO::print("Builder 1.0\n"
+                       "Copyright © 2006-2013  Mikkosoft Productions, Mikko Rasa\n"
+                       "Licensed under the GPL\n\n"
+                       "%s", helpmsg);
                package_help();
                return 0;
        }
@@ -326,30 +327,17 @@ bool BuilderCLI::prepare_build()
        return true;
 }
 
-void BuilderCLI::usage(const char *reason, const char *argv0, bool brief)
-{
-       if(reason)
-               IO::print(IO::cerr, "%s\n", reason);
-
-       if(brief)
-               IO::print(IO::cerr, "Usage: %s\n", usagemsg);
-       else
-       {
-               IO::print(IO::cerr, "Builder 1.0\n\n");
-               IO::print(IO::cerr, "Usage: %s [options] [<target> ...]\n\n", argv0);
-               IO::print(IO::cerr, "Options:\n");
-               IO::print(IO::cerr, helpmsg);
-       }
-}
-
 void BuilderCLI::package_help()
 {
        PackageManager &package_manager = builder.get_package_manager();
+       if(package_manager.get_packages().empty())
+               return;
+
        SourcePackage &main_pkg = dynamic_cast<SourcePackage &>(package_manager.get_main_package());
        const Config &config = main_pkg.get_config();
        const Config::OptionMap &options = config.get_options();
 
-       IO::print("Required packages:\n  ");
+       IO::print("\nRequired packages:\n  ");
        const Package::Requirements &requires = main_pkg.get_required_packages();
        for(Package::Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i)
        {
@@ -367,6 +355,3 @@ void BuilderCLI::package_help()
                IO::print("\n");
        }
 }
-
-string BuilderCLI::usagemsg;
-string BuilderCLI::helpmsg;