Skip to content

Commit

Permalink
Add a --show-copyable-inputs CLI flag
Browse files Browse the repository at this point in the history
The --show-copyable-inputs flag shows a list of installable directories
to end users in case there are several or the lists are complicated.

Also applied some drive-by const-correctness in a few related methods.

refs idaholab#19022
  • Loading branch information
permcody committed Mar 28, 2022
1 parent cb73330 commit 7fe2beb
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 19 deletions.
10 changes: 6 additions & 4 deletions framework/include/base/MooseApp.h
Expand Up @@ -1215,20 +1215,22 @@ class MooseApp : public ConsoleStreamInterface,
*/
PerfGraph & createRecoverablePerfGraph();

bool showInputs() const;

/**
* Handles the copy_inputs input parameter logic: Checks to see whether the passed argument is
* valid (a readable installed directory) and recursively copies those files into a read/writable
* location for the user.
* valid (a readable installed directory) and recursively copies those files into a
* read/writable location for the user.
* @return a Boolean value used to indicate whether the application should exit early
*/
bool copyInputs();
bool copyInputs() const;

/**
* Handles the run input parameter logic: Checks to see whether a directory exists in user space
* and launches the TestHarness to process the given directory.
* @return a Boolean value used to indicate whether the application should exit early
*/
bool runInputs();
bool runInputs() const;

/// General storage for custom RestartableData that can be added to from outside applications
std::unordered_map<RestartableDataMapName, std::pair<RestartableDataMap, std::string>>
Expand Down
5 changes: 5 additions & 0 deletions framework/include/parser/CommandLine.h
Expand Up @@ -104,6 +104,11 @@ class CommandLine
// Return an iterator to the beginning of the container of CLI options
std::vector<std::string>::const_iterator end() const;

/**
* Get the executable name.
*/
std::string getExecutableName() const;

/**
* Print the usage info for this command line
*/
Expand Down
4 changes: 2 additions & 2 deletions framework/include/utils/InputParameters.h
Expand Up @@ -264,12 +264,12 @@ class InputParameters : public Parameters
/**
* Get the syntax for a command-line parameter
*/
std::vector<std::string> getSyntax(const std::string & name);
std::vector<std::string> getSyntax(const std::string & name) const;

/**
* Get the documentation string for a parameter
*/
const std::string & getDescription(const std::string & name);
const std::string & getDescription(const std::string & name) const;

/**
* This method takes a space delimited list of parameter names and adds them to the specified
Expand Down
1 change: 0 additions & 1 deletion framework/moose.mk
Expand Up @@ -39,7 +39,6 @@ pcre_deps := $(patsubst %.cc, %.$(obj-suffix).d, $(pcre_srcfiles)) \
# hit (new getpot parser)
#
HIT_DIR ?= $(MOOSE_DIR)/framework/contrib/hit
#$(info Using HIT from $(HIT_DIR))
hit_CONTENT := $(shell ls $(HIT_DIR) 2> /dev/null)
ifeq ($(hit_CONTENT),)
$(error The HIT input file parser does not seem to be available. If set, make sure the HIT_DIR environment variable is set to the correct location of your HIT parser.)
Expand Down
35 changes: 32 additions & 3 deletions framework/src/base/MooseApp.C
Expand Up @@ -50,6 +50,7 @@
#include "CommonOutputAction.h"
#include "CastUniquePointer.h"
#include "NullExecutor.h"
#include "MooseRevision.h"

// Regular expression includes
#include "pcrecpp.h"
Expand Down Expand Up @@ -153,6 +154,11 @@ MooseApp::validParams()
"--check-input",
false,
"Check the input file (i.e. requires -i <filename>) and quit.");
params.addCommandLineParam<std::string>(
"show_inputs",
"--show-copyable-inputs",
"Shows the directories able to be installed (copied) into a user-writable location");

params.addCommandLineParam<std::string>("copy_inputs",
"--copy-inputs <dir>",
"Copies installed inputs (e.g. tests, examples, etc.) to "
Expand Down Expand Up @@ -1377,7 +1383,7 @@ MooseApp::run()
return;
}

if (copyInputs() || runInputs())
if (showInputs() || copyInputs() || runInputs())
{
_ready_to_exit = true;
return;
Expand Down Expand Up @@ -1408,7 +1414,28 @@ MooseApp::run()
}

bool
MooseApp::copyInputs()
MooseApp::showInputs() const
{
if (isParamValid("show_inputs"))
{
auto copy_syntax = _pars.getSyntax("copy_inputs");
std::vector<std::string> dirs;
MooseUtils::tokenize(MOOSE_INSTALLABLE_DIRS, dirs, 1, " ");
mooseAssert(!copy_syntax.empty(), "copy_inputs sytnax should not be empty");
mooseAssert(!dirs.empty(), "MOOSE_INSTALLBLE_DIRS should not be empty");

Moose::out << "The following directories are installable into a user-writeable directory:\n\n"
<< MOOSE_INSTALLABLE_DIRS << '\n'
<< "\nTo install one or more directories of inputs, execute the binary with the \""
<< copy_syntax[0] << "\" flag. e.g.:\n$ " << _command_line->getExecutableName()
<< ' ' << copy_syntax[0] << ' ' << dirs[0] << '\n';
return true;
}
return false;
}

bool
MooseApp::copyInputs() const
{
if (isParamValid("copy_inputs"))
{
Expand Down Expand Up @@ -1441,6 +1468,8 @@ MooseApp::copyInputs()

std::string cmd = "mkdir -p " + dst_dir + "; cp -R " + src_dir + " " + dst_dir;

TIME_SECTION("copy_inputs", 2, "Copying Inputs");

// Only perform the copy on the root processor
int return_value = 0;
if (processor_id() == 0)
Expand All @@ -1456,7 +1485,7 @@ MooseApp::copyInputs()
}

bool
MooseApp::runInputs()
MooseApp::runInputs() const
{
if (isParamValid("run"))
{
Expand Down
11 changes: 8 additions & 3 deletions framework/src/parser/CommandLine.C
Expand Up @@ -247,14 +247,19 @@ CommandLine::search(const std::string & option_name)
mooseError("Unrecognized option name: ", option_name);
}

void
CommandLine::printUsage() const
std::string
CommandLine::getExecutableName() const
{
// Grab the first item out of argv
std::string command(_args[0]);
command.substr(command.find_last_of("/\\") + 1);
return command;
}

Moose::out << "Usage: " << command << " [<options>]\n\n"
void
CommandLine::printUsage() const
{
Moose::out << "Usage: " << getExecutableName() << " [<options>]\n\n"
<< "Options:\n"
<< std::left;

Expand Down
14 changes: 9 additions & 5 deletions framework/src/utils/InputParameters.C
Expand Up @@ -688,9 +688,12 @@ InputParameters::addParamNamesToGroup(const std::string & space_delim_names,
}

std::vector<std::string>
InputParameters::getSyntax(const std::string & name)
InputParameters::getSyntax(const std::string & name) const
{
return _params[name]._cli_flag_names;
auto it = _params.find(name);
if (it == _params.end())
mooseError("No parameter exists with the name ", name);
return it->second._cli_flag_names;
}

std::string
Expand Down Expand Up @@ -855,11 +858,12 @@ InputParameters::isParamSetByUser(const std::string & name) const
}

const std::string &
InputParameters::getDescription(const std::string & name)
InputParameters::getDescription(const std::string & name) const
{
if (_params.count(name) == 0)
auto it = _params.find(name);
if (it == _params.end())
mooseError("No parameter exists with the name ", name);
return _params[name]._doc_string;
return it->second._doc_string;
}

template <>
Expand Down
8 changes: 8 additions & 0 deletions modules/doc/content/application_development/build_system.md
Expand Up @@ -259,6 +259,14 @@ $ cd <directory>
$ bison-opt --run -j8 # Note: Command line parameters appearing after --run are passed to the TestHarness
```

For a complete list of the directories that may be copied use the `--show-copyable-inputs` flag.

Example:

```
$ bison-opt --show-copyable-inputs
```

When using INL HPC systems to run your input, you will load a module that will set your path correctly.

Example:
Expand Down
1 change: 0 additions & 1 deletion test/Makefile
Expand Up @@ -22,7 +22,6 @@ APPLICATION_NAME := moose_test
BUILD_EXEC := yes
BUILD_TEST_OBJECTS_LIB := no
GEN_REVISION := no
INSTALLABLE_DIRS := tests/misc
include $(FRAMEWORK_DIR)/app.mk

###############################################################################
Expand Down

0 comments on commit 7fe2beb

Please sign in to comment.