Skip to content

Commit

Permalink
Changes to ease the integration with sphinx-argparse
Browse files Browse the repository at this point in the history
  • Loading branch information
paulaidt committed Feb 14, 2024
1 parent 60452a0 commit 10e7799
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions wfexs_backend/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from typing import (
Callable,
Sequence,
Tuple,
Type,
Union,
)
Expand Down Expand Up @@ -881,8 +882,11 @@ def processExportCommand(

return retval

def get_wfexs_argparse() -> "argparse.ArgumentParser":
retval, _ = _get_wfexs_argparse_internal(docgen=True)
return retval

def main() -> None:
def _get_wfexs_argparse_internal(docgen: "bool") -> "Tuple[argparse.ArgumentParser, str]":
verstr = get_WfExS_version_str()

defaultLocalConfigFilename = os.environ.get("WFEXS_CONFIG_FILE")
Expand All @@ -894,6 +898,9 @@ def main() -> None:
defaultLocalConfigFilename = os.path.join(
os.getcwd(), defaultLocalConfigFilename
)

rawpre = "" if docgen else "raw|"

ap = argparse.ArgumentParser(
description="WfExS (workflow execution service) backend " + verstr,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand Down Expand Up @@ -958,7 +965,7 @@ def main() -> None:
ap_c = genParserSub(sp, WfExS_Commands.Cache)
ap_c.add_argument(
"cache_command",
help="raw|Cache command to perform\n\n"
help=f"{rawpre}Cache command to perform\n\n"
+ "\n".join(
map(lambda c: f"{c.value:<12}{c.description}", WfExS_Cache_Commands) # type: ignore[attr-defined]
),
Expand Down Expand Up @@ -989,7 +996,7 @@ def main() -> None:
)
ap_c.add_argument(
"cache_type",
help="raw|Cache type to perform the cache command\n\n"
help=f"{rawpre}Cache type to perform the cache command\n\n"
+ "\n".join(map(lambda c: f"{c.value:<12}{c.description}", WfExS_CacheType)), # type: ignore[attr-defined]
type=cast("Callable_WfExS_CacheType", WfExS_CacheType.argtype),
choices=WfExS_CacheType,
Expand All @@ -1001,7 +1008,7 @@ def main() -> None:
ap_w = genParserSub(sp, WfExS_Commands.StagedWorkDir, crateParams=True)
ap_w.add_argument(
"staged_workdir_command",
help="raw|Staged working directory command to perform\n\n"
help=f"{rawpre}Staged working directory command to perform\n\n"
+ "\n".join(
map(
lambda c: f"{c.value:<16}{c.description}", WfExS_Staged_WorkDir_Commands # type: ignore[attr-defined]
Expand Down Expand Up @@ -1032,7 +1039,7 @@ def main() -> None:
)
ap_expt.add_argument(
"export_contents_command",
help="raw|Export operations from staged working directory to perform\n\n"
help=f"{rawpre}Export operations from staged working directory to perform\n\n"
+ "\n".join(
map(lambda c: f"{c.value:<16}{c.description}", WfExS_Export_Commands) # type: ignore[attr-defined]
),
Expand Down Expand Up @@ -1073,6 +1080,11 @@ def main() -> None:
sp, WfExS_Commands.ExportCrate, postStageParams=True, crateParams=True
)

return ap, defaultLocalConfigFilename

def main() -> None:
ap, defaultLocalConfigFilename = _get_wfexs_argparse_internal(docgen=False)

args = ap.parse_args()

fullHelp = args.fullHelp
Expand Down

0 comments on commit 10e7799

Please sign in to comment.