コード例 #1
0
ファイル: main.cpp プロジェクト: srpgilles/pict_stock
int main(int argc, char* argv[])
{
	LoggingFacility logs;

	bool doAskModifyDate(false);

	GetOpt::Parser parser;
	String parameterFile;
	parser.addParagraph("\nUsual option(s):\n");
	parser.add(parameterFile, ' ', "parameter_file", "Parameters file. If not precised "
		"parameters.ini in current folder is attempted.");
	parser.addParagraph("\nVery seldom and specific option(s):\n");
	AnyString description("If this flag is present, ask whenever a new folder is scanner for"
		" new photos whether a date is to be manually entered; if so the exif of the pictures "
		" inside that directory will be modified if the date doesn't match the date already there. "
		"This is useful for instance when applying the program to photos which exif date are "
		"uncertain but date are known are known otherwise.");
	parser.addFlag(doAskModifyDate, ' ', "do_ask_modify_date", description);
	parser.addParagraph("\nHelp:\n");

	if (!parser(argc, argv))
		exit(EXIT_FAILURE);

	// Default values
	if (parameterFile.empty())
		parameterFile = "parameters.ini";


	try
	{
		typedef GenericTools::ReadParameterFile::KeyString KeyString;
		std::list<KeyString> keys;
		keys.push_back("inputFolder");
		keys.push_back("outputFolder");
		keys.push_back("pathFormat");
		keys.push_back("logFile");

		GenericTools::SqliteWrapper db("test.db3", SQLITE_OPEN_READWRITE);

		ExtendedPhoto::Cameras cameras(db);

		const GenericTools::ReadParameterFile parameters(logs, parameterFile, keys);
		PhotoDirectory::PhotoDirectory photoDirectory(logs, cameras, parameters["outputFolder"], parameters["pathFormat"]);
		SortNewPhotos::SortNewPhotos sortNewPhotos(logs, cameras, parameters["inputFolder"], photoDirectory,
			parameters["logFile"], doAskModifyDate);

		if (!sortNewPhotos.proceed())
			return EXIT_FAILURE; 
	}
	catch(const std::exception& e)
	{
		std::cout << "EXCEPTION: " << e.what() << '\n';
		exit(EXIT_FAILURE);
	}

	return 0;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: erdincay/libyuni
int main(int argc, char* argv[])
{
    // The command line options parser
    GetOpt::Parser options;

    // A simple option : --text
    String optText;
    options.add(optText, 't', "text");

    // For the help, we want to display _our_ help usage
    // For that, we have to override the option `--help`
    bool optHelp = false;
    options.addFlag(optHelp, 'h', "help");

    // But, do not forget to do the same thing for `?` on
    // Windows, for compatibility with other programs.
    // Example: getopt_04_customhelpusage.exe /?
# ifdef YUNI_OS_WINDOWS
    // It is safe to use the same variable `optFlag`
    options.addFlag(optHelp, '?');
# endif


    // Ask the parser to parse the command line
    if (!options(argc, argv))
    {
        // The program should not continue here
        return (options.errors() ? 1 /* error */ : 0);
    }


    if (optHelp)
    {
        std::cout <<
                  "This is our custom help usage.\n"
                  "Here is the list of options :\n\n"
                  " -t, --text=VALUE : A text to display\n\n";
        return 0;
    }

    std::cout << "Text : `" << optText << "`" << std::endl;

    return 0;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: MAPJe71/libyuni
int main(int argc, char* argv[])
{
	// The command line options parser
	GetOpt::Parser options;

	// A simple option : --title="<X>" or -t "<X>"
	// We have to provide the variable where the given value on the command line
	// will be written
	String optText = "A default value";
	// Adding the option to the parser :
	// <variable>    : the variable where the user data will be written
	// 't'           : The short name of the option (./getopt_00_simple -t "my value")
	// "text"        : The long name of the option  (./getopt_00_simple --text "my value")
	// <description> : The description of the option, that will be displayed in the help usage
	options.add(optText, 't', "title", "An option with a parameter");

	// A simple flag, enabled when the option is present on the command line
	// Example: ./getopt_00_simple --verbose
	bool optVerbose = false;
	options.addFlag(optVerbose, 'v', "verbose", "A simple flag");


	// Ask to the parser to parse the command line
	if (not options(argc, argv))
	{
		// The program should not continue here
		// The user may have requested the help or an error has happened
		// If an error has happened, the exit status should be different from 0
		if (options.errors())
		{
			std::cout << "Abort due to error" << std::endl;
			return 1;
		}
		return 0;
	}

	// Displaying the value of our variable on the standard output
	std::cout << "Value for `optText` : `" << optText << "`" << std::endl;
	std::cout << "Verbose             : " << optVerbose << std::endl;

	return 0;
}
コード例 #4
0
	bool LibConfigProgram::parseCommandLine(int argc, char** argv)
	{
		// The Command line parser
		GetOpt::Parser opts;

		// Compiler
		opts.addParagraph("\nTypical usage example :\n  $ yuni-config -c gcc -m script --cxxflags\n\nCompiler settings:");
		opts.addFlag(pOptCxxFlags, ' ', "cxxflags", "Print the CXX flags (*)");
		opts.addFlag(pOptLibFlags, ' ', "libs", "Print the Libs flags (*)");
		opts.add(pOptCompiler, 'c', "compiler", "Set the target compiler (gcc,msvc,mingw,icc,...)");
		opts.addFlag(pOptPrintCompilerByDefault, ' ', "compiler-default", "Print the compiler used by default and exit");

		// All required modules
		opts.addParagraph("\nModules:");
		opts.add(pOptModules, 'm', "modules", "Add one or several requested modules (*)");
		opts.addFlag(pOptModuleList, ' ', "module-list", "Print all available modules of the selected version and exit (*)");
		opts.addFlag(pOptPrintModulesDeps, ' ', "module-deps", "Print all modules and the dependencies required and exit (*)");

		// Prefix
		opts.addParagraph("\nSearching paths:");
		opts.add(pOptPrefix, 'p', "prefix", "Add a prefix folder for searching available versions of libyuni");
		opts.addFlag(pOptNoDefaultPath, ' ', "no-default-path", "Do not use the default paths to find available versions of libyuni");
		opts.addFlag(pOptDefaultPathList, ' ', "default-path-list", "Print the default paths that would be used and exit (empty if 'no-default-path' is enabled)");

		opts.addParagraph("\nVersions:");
		opts.addFlag(pOptList, 'l', "list", "Print the list of all versions of libyuni which have been found (with complete informations) and exit");
		opts.addFlag(pOptListOnlyVersions, ' ', "list-only-versions", "Print the list of all versions of libyuni which have been found and exit");

		// Help
		opts.addParagraph("\nHelp\n  * : Option related to the selected version of libyuni");
		bool quiet = false;
		opts.addFlag(quiet, ' ', "quiet", "Suppress error messages");
		opts.addFlag(pOptDebug, ' ', "debug", "Print debug messages");
		opts.addFlag(pOptVersion, 'v', "version", "Print the version and exit");

		if (!opts(argc, argv))
		{
			pExitStatus = opts.errors() ? 1 /*error*/ : 0;
			if ((pOptPrintErrors and not quiet) || pOptDebug)
				std::cout << "Error when parsing the command line\n";
			return false;
		}

		if (quiet)
			pOptPrintErrors = false;

		if (pOptPrintCompilerByDefault)
		{
			std::cout << YUNI_LIBCONFIG_DEFAULT_COMPILER << "\n";
			return false;
		}

		// Clean the prefix paths (make them absolute)
		pVersionList.debug(pOptDebug);
		cleanPrefixPaths();
		normalizeCompiler();

		return true;
	}