Changeset 1882


Ignore:
Timestamp:
Mar 30, 2009, 11:24:55 PM (12 years ago)
Author:
Peter
Message:

updated example of class CommandLine?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.5-stable/yat/utility/CommandLine.h

    r1797 r1882  
    5151 
    5252     CommandLine cmd;
    53      OptionArg<std::string> dir(cmd, "d,dir", "output directory");
    5453     OptionHelp help(cmd);
     54     OptionInFile in(cmd, "i,in",
     55                     "Read input from file (rather than standard input)");
     56     OptionOutFile out(cmd, "o,out", "Place the output to file");
    5557     OptionSwitch target(cmd, "T,target", "treat DEST as a normal file", true);
    5658     OptionSwitch verbose(cmd, "v,verbose", "explain what is being done");
    5759     OptionSwitch version(cmd, "version", "output version and exit");
     60     std::stringstream copyright;
     61     copyright << cmd.program_name() << " 1.0\n"
     62               << "Copyright (C) 2007 Peter Johansson\n\n"
     63               << "This is free software see the source for copying "
     64               << "conditions. There is NO\nwarranty; not even for "
     65               << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
    5866     try {
    5967       cmd.parse(argc, argv);
     
    6169     catch (cmd_error& e){
    6270       if (version.present()){
    63          std::cout << cmd.program_name() << " 1.0\n"
    64                    << "Copyright (C) 2007 Peter Johansson\n\n"
    65                    << "This is free software see the source for copying "
    66                    << "conditions. There is NO\nwarranty; not even for "
    67                    << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
    68          exit(0);
     71         std::cout << copyright.str();     
     72         return EXIT_SUCCESS;
    6973       }
    70        std::cout << e.what() << std::endl;
    71        return 1;
     74       std::cerr << e.what() << std::endl;
     75       return EXIT_FAILURE;
    7276     } 
     77     if (version.present()){
     78       std::cout << copyright.str();     
     79       return EXIT_SUCCESS;
     80     }
    7381     ...
    7482     \endcode
Note: See TracChangeset for help on using the changeset viewer.