X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbuildercli.cpp;h=0bdf8777d0f51cfb5909821d0b119db0ccfc0860;hb=3ab5bb78c8ca2d71d9902dab34209670eac341af;hp=bcd439e854c6fc9afb05df7832c0e192c3f87845;hpb=1dad660f7bbda5ef3239fd6374e0f8a77e19eaaa;p=builder.git diff --git a/source/buildercli.cpp b/source/buildercli.cpp index bcd439e..0bdf877 100644 --- a/source/buildercli.cpp +++ b/source/buildercli.cpp @@ -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])+" [ ...]"; - 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] [ ...]\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(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;