Skip to content

Commit

Permalink
replace 'input' and 'output' fields with "in_file" and "out_file" to …
Browse files Browse the repository at this point in the history
…make it more pydronic
  • Loading branch information
tclose committed Feb 22, 2024
1 parent 86271ff commit ea3d590
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions core/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,14 +804,13 @@ std::string pydra_usage() {
if (!result.size() && c == '5') {
result += "Five"; // handle 5tt prefixes so they don't create invalid Python identifiers
capitalizeNext = false;
} else if (capitalizeNext) {
} else if (std::isalpha(c) && capitalizeNext) {
result += std::toupper(c);
capitalizeNext = false;
} else if (c == '2' && result.size() > 2) {
capitalizeNext = true;
result += c;
} else {
result += c;
if (c == '2')
capitalizeNext = true;
for (const std::string &prefix : CMD_PREFIXES) {
if (result == prefix) {
capitalizeNext = true;
Expand Down Expand Up @@ -1015,14 +1014,31 @@ std::string pydra_usage() {
return f;
};

auto format_arg_name = [&](const Argument &arg) {
std::string id = arg.id;
std::string arg_name;
if (id == "input" && (arg.type == ImageIn || arg.type == ArgFileIn))
arg_name = "in_file";
else if (id == "input" && arg.type == ArgDirectoryIn)
arg_name = "in_dir";
else if (id == "output" && (arg.type == ImageOut || arg.type == ArgFileOut))
arg_name = "out_file";
else if (id == "output" && arg.type == ArgDirectoryOut)
arg_name = "out_dir";
else
arg_name = escape_id(arg.id);
return arg_name;
};

// Print out input spec
s += "\n\ninput_fields = [\n\n" + base_indent + "# Arguments\n";
for (size_t i = 0; i < ARGUMENTS.size(); ++i) {

bool is_multi = (ARGUMENTS[i].flags & AllowMultiple) && (ARGUMENTS[i].type != ArgFileOut);
s += base_indent + "(\n";
// Print name of field
s += indent + "\"" + escape_id(ARGUMENTS[i].id) + "\",\n";
std::string arg_name = format_arg_name(ARGUMENTS[i]);
s += indent + "\"" + arg_name + "\",\n";
// Print type
s += indent;
if (is_multi) {
Expand All @@ -1038,8 +1054,7 @@ std::string pydra_usage() {
s += md_indent + "\"position\": " + std::to_string(i) + ",\n";
bool output_type = false;
if (ARGUMENTS[i].type == ImageOut || ARGUMENTS[i].type == ArgFileOut || ARGUMENTS[i].type == ArgDirectoryOut) {
s += md_indent + "\"output_file_template\": \"" +
format_output_template(escape_id(ARGUMENTS[i].id), ARGUMENTS[i].type) + "\",\n";
s += md_indent + "\"output_file_template\": \"" + format_output_template(arg_name, ARGUMENTS[i].type) + "\",\n";
output_type = true;
}
s += md_indent + "\"help_string\": \"\"\"" + ARGUMENTS[i].desc + "\"\"\",\n";
Expand Down Expand Up @@ -1089,7 +1104,7 @@ std::string pydra_usage() {
bool is_multi = ARGUMENTS[i].flags & AllowMultiple;
s += base_indent + "(\n";
// Print name of field
s += indent + "\"" + escape_id(ARGUMENTS[i].id) + "\",\n";
s += indent + "\"" + format_arg_name(ARGUMENTS[i]) + "\",\n";
// Print type
std::string type_string;
if (is_multi)
Expand Down

0 comments on commit ea3d590

Please sign in to comment.