Split command line parsing to separate directory.
authorTeemu Murtola <teemu.murtola@gmail.com>
Sat, 21 Apr 2012 08:07:34 +0000 (11:07 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Sat, 21 Apr 2012 08:36:42 +0000 (11:36 +0300)
Part of IssueID #666.

Change-Id: Ia4969f636fbf6a3b00a9859d6705fc7375f0eb36

15 files changed:
src/gromacs/CMakeLists.txt
src/gromacs/commandline.h [new file with mode: 0644]
src/gromacs/commandline/CMakeLists.txt [new file with mode: 0644]
src/gromacs/commandline/cmdlinehelpwriter-impl.h [moved from src/gromacs/options/cmdlinehelpwriter-impl.h with 92% similarity]
src/gromacs/commandline/cmdlinehelpwriter.cpp [moved from src/gromacs/options/cmdlinehelpwriter.cpp with 98% similarity]
src/gromacs/commandline/cmdlinehelpwriter.h [moved from src/gromacs/options/cmdlinehelpwriter.h with 94% similarity]
src/gromacs/commandline/cmdlineparser-impl.h [moved from src/gromacs/options/cmdlineparser-impl.h with 88% similarity]
src/gromacs/commandline/cmdlineparser.cpp [moved from src/gromacs/options/cmdlineparser.cpp with 98% similarity]
src/gromacs/commandline/cmdlineparser.h [moved from src/gromacs/options/cmdlineparser.h with 96% similarity]
src/gromacs/commandline/tests/CMakeLists.txt [new file with mode: 0644]
src/gromacs/commandline/tests/cmdlineparser.cpp [moved from src/gromacs/options/tests/cmdlineparser.cpp with 98% similarity]
src/gromacs/options.h
src/gromacs/options/tests/CMakeLists.txt
src/gromacs/trajectoryanalysis/cmdlinerunner.cpp
src/testutils/testoptions.cpp

index aedc5a11802a0bec1d19a9963a78e488b6159cae..e0c606994ea708e83d82e97f93f4d20e04d0b1c2 100644 (file)
@@ -5,6 +5,7 @@ add_subdirectory(gmxlib)
 add_subdirectory(mdlib)
 add_subdirectory(gmxpreprocess)
 add_subdirectory(analysisdata)
+add_subdirectory(commandline)
 add_subdirectory(options)
 add_subdirectory(selection)
 add_subdirectory(trajectoryanalysis)
diff --git a/src/gromacs/commandline.h b/src/gromacs/commandline.h
new file mode 100644 (file)
index 0000000..0a55999
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ *
+ *                This source code is part of
+ *
+ *                 G   R   O   M   A   C   S
+ *
+ *          GROningen MAchine for Chemical Simulations
+ *
+ * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2009, The GROMACS development team,
+ * check out http://www.gromacs.org for more information.
+
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * If you want to redistribute modifications, please consider that
+ * scientific software is very special. Version control is crucial -
+ * bugs must be traceable. We will be happy to consider code for
+ * inclusion in the official distribution, but derived work must not
+ * be called official GROMACS. Details are found in the README & COPYING
+ * files - if they are missing, get the official version at www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the papers on the package - you can find them in the top README file.
+ *
+ * For more info, check our website at http://www.gromacs.org
+ */
+/*! \defgroup module_commandline Command Line Parsing and Help
+ * \ingroup group_utilitymodules
+ * \brief
+ * Provides functionality for parsing command-line arguments and writing help.
+ *
+ * This module implements gmx::CommandLineParser that assigns values to
+ * gmx::Options (see \ref module_options) based on command-line arguments.
+ * gmx::CommandLineHelpWriter is also provided to write help text for a program
+ * that uses the parser.
+ *
+ * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ */
+/*! \file
+ * \brief
+ * Public API convenience header for handling command-line parameters.
+ *
+ * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \inpublicapi
+ * \ingroup module_commandline
+ */
+#ifndef GMX_COMMANDLINE_H
+#define GMX_COMMANDLINE_H
+
+#include "commandline/cmdlinehelpwriter.h"
+#include "commandline/cmdlineparser.h"
+
+#endif
diff --git a/src/gromacs/commandline/CMakeLists.txt b/src/gromacs/commandline/CMakeLists.txt
new file mode 100644 (file)
index 0000000..4a27d0d
--- /dev/null
@@ -0,0 +1,13 @@
+file(GLOB COMMANDLINE_SOURCES *.cpp)
+set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${COMMANDLINE_SOURCES} PARENT_SCOPE)
+
+set(COMMANDLINE_PUBLIC_HEADERS
+    cmdlinehelpwriter.h
+    cmdlineparser.h)
+install(FILES ${COMMANDLINE_PUBLIC_HEADERS}
+        DESTINATION ${INCL_INSTALL_DIR}/gromacs/commandline
+        COMPONENT development)
+
+if (BUILD_TESTING)
+    add_subdirectory(tests)
+endif (BUILD_TESTING)
similarity index 92%
rename from src/gromacs/options/cmdlinehelpwriter-impl.h
rename to src/gromacs/commandline/cmdlinehelpwriter-impl.h
index 8665e70068be5c52702ede0b358f5c8c98d3d0ae..287d024e986fe066acee0f9590ddbd520c3a90df 100644 (file)
  * Declares private implementation class for gmx::CommandLineHelpWriter.
  *
  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
- * \ingroup module_options
+ * \ingroup module_commandline
  */
-#ifndef GMX_OPTIONS_CMDLINEHELPWRITER_IMPL_H
-#define GMX_OPTIONS_CMDLINEHELPWRITER_IMPL_H
+#ifndef GMX_COMMANDLINE_CMDLINEHELPWRITER_IMPL_H
+#define GMX_COMMANDLINE_CMDLINEHELPWRITER_IMPL_H
 
 #include "cmdlinehelpwriter.h"
 
@@ -48,7 +48,7 @@ class Options;
 /*! \internal \brief
  * Private implementation class for CommandLineHelpWriter.
  *
- * \ingroup module_options
+ * \ingroup module_commandline
  */
 class CommandLineHelpWriter::Impl
 {
similarity index 98%
rename from src/gromacs/options/cmdlinehelpwriter.cpp
rename to src/gromacs/commandline/cmdlinehelpwriter.cpp
index dab95d85dcd9cc9e7eed5a87943bc2fdbdaa6aea..21561530eec78cc71185865d27966a14979623bb 100644 (file)
@@ -33,9 +33,9 @@
  * Implements gmx::CommandLineHelpWriter.
  *
  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
- * \ingroup module_options
+ * \ingroup module_commandline
  */
-#include "gromacs/options/cmdlinehelpwriter.h"
+#include "cmdlinehelpwriter.h"
 
 #include <cstdio>
 #include <cstdlib>
@@ -62,7 +62,7 @@ namespace
 /*! \internal \brief
  * Helper object for writing section descriptions to help.
  *
- * \ingroup module_options
+ * \ingroup module_commandline
  */
 class DescriptionWriter : public OptionsVisitor
 {
@@ -101,7 +101,7 @@ void DescriptionWriter::visitSubSection(const Options &section)
 /*! \internal \brief
  * Helper object for writing help for file parameters.
  *
- * \ingroup module_options
+ * \ingroup module_commandline
  */
 class FileParameterWriter : public OptionsTypeVisitor<FileNameOptionInfo>
 {
@@ -202,7 +202,7 @@ void FileParameterWriter::visitOptionType(const FileNameOptionInfo &option)
 /*! \internal \brief
  * Helper object for writing help for non-file parameters.
  *
- * \ingroup module_options
+ * \ingroup module_commandline
  */
 class ParameterWriter : public OptionsVisitor
 {
similarity index 94%
rename from src/gromacs/options/cmdlinehelpwriter.h
rename to src/gromacs/commandline/cmdlinehelpwriter.h
index 0cac3db64bec62c337ef04e4dd31444383bfd993..763a3440cd48bcbbb3af7f6118d9e52a29f8deba 100644 (file)
  *
  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
  * \inpublicapi
- * \ingroup module_options
+ * \ingroup module_commandline
  */
-#ifndef GMX_OPTIONS_CMDLINEHELPWRITER_H
-#define GMX_OPTIONS_CMDLINEHELPWRITER_H
+#ifndef GMX_COMMANDLINE_CMDLINEHELPWRITER_H
+#define GMX_COMMANDLINE_CMDLINEHELPWRITER_H
 
 #include <cstdio>
 
@@ -52,7 +52,7 @@ class Options;
  * Writes help information for Options in ascii format.
  *
  * \inpublicapi
- * \ingroup module_options
+ * \ingroup module_commandline
  */
 class CommandLineHelpWriter
 {
similarity index 88%
rename from src/gromacs/options/cmdlineparser-impl.h
rename to src/gromacs/commandline/cmdlineparser-impl.h
index b87f458a25cf13217fe9dbde783b2b052f6cdda8..5a0640a21dc6c65bcbc1e1c68a2120a03b34d148 100644 (file)
  * Declares private implementation class for gmx::CommandLineParser.
  *
  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
- * \ingroup module_options
+ * \ingroup module_commandline
  */
-#ifndef GMX_OPTIONS_CMDLINEPARSER_IMPL_H
-#define GMX_OPTIONS_CMDLINEPARSER_IMPL_H
+#ifndef GMX_COMMANDLINE_CMDLINEPARSER_IMPL_H
+#define GMX_COMMANDLINE_CMDLINEPARSER_IMPL_H
 
 #include "cmdlineparser.h"
-#include "optionsassigner.h"
+#include "../options/optionsassigner.h"
 
 namespace gmx
 {
@@ -47,13 +47,13 @@ namespace gmx
 /*! \internal \brief
  * Private implementation class for CommandLineParser.
  *
- * \ingroup module_options
+ * \ingroup module_commandline
  */
 class CommandLineParser::Impl
 {
     public:
         //! Sets the options object to parse to.
-        Impl(Options *options);
+        explicit Impl(Options *options);
 
         //! Helper object for assigning the options.
         OptionsAssigner         _assigner;
similarity index 98%
rename from src/gromacs/options/cmdlineparser.cpp
rename to src/gromacs/commandline/cmdlineparser.cpp
index 3ab7e2afc857b53ed980a6703b520264790e2cea..02d1c784816e90ceec4f947468fa6da587f2b600 100644 (file)
@@ -33,9 +33,9 @@
  * Implements gmx::CommandLineParser.
  *
  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
- * \ingroup module_options
+ * \ingroup module_commandline
  */
-#include "gromacs/options/cmdlineparser.h"
+#include "cmdlineparser.h"
 
 #include <cctype>
 
similarity index 96%
rename from src/gromacs/options/cmdlineparser.h
rename to src/gromacs/commandline/cmdlineparser.h
index cc2ea2304b8ec292712d77670b27b1137a84d699..d5b0ac24cf67626771b9d4b381bdb358729fece7 100644 (file)
  *
  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
  * \inpublicapi
- * \ingroup module_options
+ * \ingroup module_commandline
  */
-#ifndef GMX_OPTIONS_CMDLINEPARSER_H
-#define GMX_OPTIONS_CMDLINEPARSER_H
+#ifndef GMX_COMMANDLINE_CMDLINEPARSER_H
+#define GMX_COMMANDLINE_CMDLINEPARSER_H
 
 #include <string>
 #include <vector>
@@ -62,7 +62,7 @@ options.finish();
  * \endcode
  *
  * \inpublicapi
- * \ingroup module_options
+ * \ingroup module_commandline
  */
 class CommandLineParser
 {
diff --git a/src/gromacs/commandline/tests/CMakeLists.txt b/src/gromacs/commandline/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..862bd11
--- /dev/null
@@ -0,0 +1,2 @@
+add_gtest_test(CommandLineUnitTests commandline-test
+               cmdlineparser.cpp)
similarity index 98%
rename from src/gromacs/options/tests/cmdlineparser.cpp
rename to src/gromacs/commandline/tests/cmdlineparser.cpp
index f700668c9ad0375360e8745ded913b9ff4b819af..f33c46a129481b8bd288ab490c5efb56354ea2f8 100644 (file)
@@ -36,7 +36,7 @@
  * catch errors in other parts than just in command-line parsing.
  *
  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
- * \ingroup module_options
+ * \ingroup module_commandline
  */
 #include <cstdlib>
 #include <cstring>
@@ -44,8 +44,8 @@
 
 #include <gtest/gtest.h>
 
+#include "gromacs/commandline/cmdlineparser.h"
 #include "gromacs/options/basicoptions.h"
-#include "gromacs/options/cmdlineparser.h"
 #include "gromacs/options/options.h"
 
 namespace
index e8f6aa22f4d295a41eec37fab48716dce25847bc..6f0797cae250e23e95cf51e439e4cf5e40f1ba7f 100644 (file)
  * Basic interface for providing options is implemented by the Options class
  * and classes defined in basicoptions.h for specifying individual options.
  * Only these are needed if a class wants to provide a set of standard options.
+ * When creating an Options object and adding options, it is possible to add
+ * descriptions for individual options as well as for the whole set of options.
+ * These can then be used to write out help text.
  *
- * Values for options can be set using option parsers.
- * Currently, only one is defined: CommandLineParser.
- * As the name suggests, this parser gets values from command-line arguments.
- * Multiple parsers can be used in sequence to provide option values from
- * multiple sources; in such cases, if an option is provided in multiple
- * sources, new values overwrite any values from previous sources.
- *
- * In most cases, it is desirable to be able to provide a help describing the
- * available options.  When creating an Options object and adding options, it
- * is possible to add descriptions for individual options as well as for the
- * whole set of options.  These can then be used to write out a help using one
- * of the provided help writers.
- * Currently, only one is defined: CommandLineHelpWriter
- * (implementation is not yet complete).
+ * Module \ref module_commandline implements classes that assign option values
+ * from command line and produce help for programs that use the command line
+ * parser.
  *
  * \if libapi
  * <H3>Advanced Use (in library API)</H3>
index 1e0aaaed3b94c422c3cc2d127f35559491989298..ca2a9c8b3295930a4941255642befbbf8a1a98a9 100644 (file)
@@ -1,4 +1,4 @@
 add_gtest_or_gmock_test(OptionsUnitTests options-test
-                        cmdlineparser.cpp option.cpp optionsassigner.cpp
+                        option.cpp optionsassigner.cpp
                         timeunitmanager.cpp
                         GMOCK_ONLY abstractoptionstorage.cpp)
index 292156dcf8cf9f75ecb814a5925091d9041e2c1d..f3bd44c0bef17bc18aecac5f2de11fa69edf003a 100644 (file)
@@ -45,8 +45,8 @@
 #include "statutil.h"
 
 #include "gromacs/analysisdata/paralleloptions.h"
-#include "gromacs/options/cmdlinehelpwriter.h"
-#include "gromacs/options/cmdlineparser.h"
+#include "gromacs/commandline/cmdlinehelpwriter.h"
+#include "gromacs/commandline/cmdlineparser.h"
 #include "gromacs/options/options.h"
 #include "gromacs/selection/selectioncollection.h"
 #include "gromacs/selection/selectionoptioninfo.h"
index 6950931836e6a3f3985f8e33ef407d2d0c889e50..f2505787702c35ac3431ebda577d61018408863f 100644 (file)
@@ -46,7 +46,7 @@
 
 #include <boost/scoped_ptr.hpp>
 
-#include "gromacs/options/cmdlineparser.h"
+#include "gromacs/commandline/cmdlineparser.h"
 #include "gromacs/options/options.h"
 #include "gromacs/utility/errorcodes.h"
 #include "gromacs/utility/gmxassert.h"