Repository navigation
[Feat] Add CLI variable injection (-p/--parameter) and custom INPUT path (-in/--input) (PART I) #8089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ZhouXY-PKU
wants to merge
8
commits into
develop
Choose a base branch
from
origin/ZhouXY-PKU-CMDL
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Feat] Add CLI variable injection (-p/--parameter) and custom INPUT path (-in/--input) (PART I) #8089
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7021a51
feat: -p/--param to enable commandline parameter input and -in to set…
ZhouXY-PKU 4eb3876
Change --param to --parameter.
ZhouXY-PKU 1be3103
Update Makefile.Objects
ZhouXY-PKU d3165ed
Fix CLI validation, input path summaries and PART I diagnostics
ABACUS-PR-BOT dff4d7e
Remove extra trailing blank lines from CLI sources
ABACUS-PR-BOT 235a7e3
Merge develop and preserve PART I CLI integration
ABACUS-PR-BOT cee3993
Merge branch 'develop' into origin/ZhouXY-PKU-CMDL
ZhouXY-PKU be4beda
Merge branch 'develop' into origin/ZhouXY-PKU-CMDL
mohanchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #include "source_io/parse_command_line.h" | ||
|
|
||
| #include <cctype> | ||
| #include <cstdio> | ||
| #include <stdexcept> | ||
|
|
||
| namespace ModuleIO | ||
| { | ||
|
|
||
| int run_control_option_size(int argc, char* argv[], int index) | ||
| { | ||
| const std::string option = argv[index]; | ||
| int size = 0; | ||
| std::string required; | ||
| if (option == "-p" || option == "--parameter") | ||
| { | ||
| size = 3; | ||
| required = "<name> <value>"; | ||
| } | ||
| else if (option == "-in" || option == "--input") | ||
| { | ||
| size = 2; | ||
| required = "<file>"; | ||
| } | ||
| else if (option == "--check-input") | ||
| { | ||
| size = 1; | ||
| } | ||
| if (size > argc - index) | ||
| { | ||
| throw std::runtime_error("Option " + option + " requires " + required); | ||
| } | ||
| return size; | ||
| } | ||
|
|
||
| CommandLineArgs parse_command_line(int argc, char* argv[]) | ||
| { | ||
| CommandLineArgs args; | ||
| for (int i = 1; i < argc; ++i) | ||
| { | ||
| const std::string arg = argv[i]; | ||
| const int option_size = run_control_option_size(argc, argv, i); | ||
|
|
||
| if (option_size == 3) | ||
| { | ||
| ++i; | ||
| const std::string name = argv[i]; | ||
| if (name.empty()) | ||
| { | ||
| const std::string msg = "Invalid variable name: (empty)"; | ||
| throw std::runtime_error(msg); | ||
| } | ||
| const unsigned char first_char | ||
| = static_cast<unsigned char>(name[0]); | ||
| const bool starts_with_digit = (std::isdigit(first_char) != 0); | ||
| if (starts_with_digit) | ||
| { | ||
| const std::string msg = "Invalid variable name: " + name; | ||
| throw std::runtime_error(msg); | ||
| } | ||
| ++i; | ||
| const std::string value = argv[i]; | ||
| args.vars[name] = value; // later duplicates override earlier ones | ||
| } | ||
| else if (option_size == 2) | ||
| { | ||
| ++i; | ||
| args.input_file = argv[i]; | ||
| if (args.input_file.empty()) | ||
| { | ||
| throw std::runtime_error("Option " + arg + " requires a nonempty <file>"); | ||
| } | ||
| } | ||
| else if (option_size == 1) | ||
| { | ||
| // parse_args has already enabled ReadInput's check mode. | ||
| continue; | ||
| } | ||
| else | ||
| { | ||
| // Unreachable in normal flow: parse_args rejects unknown | ||
| // flags before this function runs. Kept as a defensive check | ||
| // so parse_command_line stays self-contained for tests. | ||
| const std::string msg = "Unknown option: " + arg; | ||
| throw std::runtime_error(msg); | ||
| } | ||
| } | ||
| return args; | ||
| } | ||
|
|
||
| void print_help(const std::string& bin) | ||
| { | ||
| std::fprintf(stderr, "Run '%s -h' for usage.\n", bin.c_str()); | ||
| } | ||
|
|
||
| } // namespace ModuleIO | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #ifndef ModuleIO_PARSE_COMMAND_LINE_H | ||
| #define ModuleIO_PARSE_COMMAND_LINE_H | ||
|
|
||
| #include <map> | ||
| #include <string> | ||
|
|
||
| namespace ModuleIO | ||
| { | ||
|
|
||
| /// Run-control options parsed after ModuleIO::parse_args. | ||
| /// | ||
| /// Flag ownership: | ||
| /// - Informational flags (-v/-i/-h/-s/--generate-parameters-yaml) | ||
| /// are owned by ModuleIO::parse_args and exit before this function. | ||
| /// - --check-input sets check mode in parse_args and is skipped here. | ||
| /// - -p/--parameter and -in/--input share token-count validation with | ||
| /// parse_args, then their values are parsed here, before MPI setup. | ||
| struct CommandLineArgs | ||
| { | ||
| // -p / --parameter <name> <value>: stored variables (repeatable). | ||
| // PART I does not apply these values to INPUT; main emits a warning. | ||
| std::map<std::string, std::string> vars; | ||
|
|
||
| // -in / --input <file> : explicit INPUT path, default "INPUT" | ||
| std::string input_file = "INPUT"; | ||
| }; | ||
|
|
||
| /// Parses -p/--parameter and -in/--input options. | ||
| /// Throws std::runtime_error on malformed arguments (parse_args has | ||
| /// already filtered unknown flags before this function is called). | ||
| CommandLineArgs parse_command_line(int argc, char* argv[]); | ||
|
|
||
| /// Number of tokens occupied by one run-control option, including its values. | ||
| /// Returns zero for other options; throws std::runtime_error for missing values. | ||
| int run_control_option_size(int argc, char* argv[], int index); | ||
|
|
||
| /// Prints a short pointer to the canonical general help on standard error. | ||
| void print_help(const std::string& bin_name); | ||
|
|
||
| } // namespace ModuleIO | ||
|
|
||
| #endif // ModuleIO_PARSE_COMMAND_LINE_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--check-inputreaches here:parse_argsonly setscheck_modeand does not exit, soabacus --check-inputnow fails with "Unknown option: --check-input" and returns 1. The header comment ("never reach this function") is wrong. Please handle/skip it and add a test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed by d3165ed (verified at dff4d7e): Restored --check-input handling, including both orders with -in. Standalone validation and combined parser tests pass. The existing MPI check-mode exit still produces a launcher error after successful validation; this was reproduced with the original merge-base CLI paths and is recorded separately from the repaired parsing behavior.
The required CPU checks passed; CI status is unavailable through the configured connector.