xdem icon indicating copy to clipboard operation
xdem copied to clipboard

[POC] simple CLI

Open adebardo opened this issue 1 year ago • 0 comments

Given that @vschaffn is making good progress this month, we will set up a simple CLI that allows for the coregistration of two DEMs with Nuth and Kaab.

Context

The purpose of this ticket is to set up the initial file that will allow xDEM to be executed via a CLI command: xdem path_ref path_sec -v. Initially, the command will not execute any functionality but will simply display output.

  • [ ] Add the file xdem_cli.py
  • [ ] Add the function get_parser
def get_parser():
    """
    ArgumentParser for xdem

    :return: parser
    """
    parser = argparse.ArgumentParser(
        description=("Compare Digital Elevation Models"),
        fromfile_prefix_chars="@",
    )

    parser.add_argument(
        "reference_dem",
        help=(
            "path to a reference dem"
        ),
    )
    
    parser.add_argument(
        "dem_to_be_aligned",
        help=(
            "path to a second dem"
        ),
    )
    
	 parser.add_argument(
	 "--loglevel",
	 default="INFO",
	 choices=("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"),
	 help="Logger level (default: INFO. Should be one of "
	 "(DEBUG, INFO, WARNING, ERROR, CRITICAL)",
	 )

    parser.add_argument(
        "--version",
        "-v",
        action="version",
        version=f"%(prog)s {xdem.__version__}",
    )

	return parser
  • [ ] add main function
def main():
    """
    Call demcompare's main
    """
    parser = get_parser()
    argcomplete.autocomplete(parser)
    args = parser.parse_args()
    # use a global try/except to cath
    xdem.run(args.reference_dem, args.dem_to_be_aligned, args.verbose)
    
if __name__ == "__main__":
    main()
  • [ ] add imports in setup.py file
  • [ ] in file init.py add function run(configfile)
def run(reference_dem: str, dem_to_be_aligned: str, verbose: bool):  
	"""
	docstring
	"""

	print("hello world")
  • [ ] in setup.cfg add
# xdem entry points cli scripts
# xdem : main cli Program
[options.entry_points]
console_scripts =
    xdem = xdem.xdem:main

Tests

  • [ ] "Add a test that runs the execution and checks the output string in a file named tests/test_cli.py"

Documentation

In folder doc/source/quickstart.md :

  • [ ] Add a section about the CLI

adebardo avatar Oct 28 '24 16:10 adebardo