Coverage for lunar_toolkit/cli/__init__.py: 84%

23 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-19 02:58 +0000

1"""``lunar`` CLI; each subcommand module exports COMMAND, add_parser(sub) and run(args).""" 

2 

3import argparse 

4import logging 

5import sys 

6 

7from . import ( 

8 app, 

9 build_db, 

10 download, 

11 kaguya, 

12 ode_search, 

13 pairs, 

14 process, 

15 query, 

16 reference, 

17 search, 

18 serve, 

19 sfs, 

20 sfs_report, 

21 shadowcam, 

22 stereo, 

23 workspace, 

24) 

25 

26_COMMANDS = [ 

27 build_db, 

28 download, 

29 query, 

30 search, 

31 ode_search, 

32 pairs, 

33 reference, 

34 process, 

35 kaguya, 

36 shadowcam, 

37 stereo, 

38 sfs, 

39 sfs_report, 

40 workspace, 

41 serve, 

42 app, 

43] 

44 

45 

46def _build_parser() -> argparse.ArgumentParser: 

47 parser = argparse.ArgumentParser( 

48 prog="lunar", 

49 description=( 

50 "Lunar imagery toolkit - build LROC index databases, search footprints, " 

51 "query ODE (ShadowCam, LROC, Kaguya TC and MI), download and import images into ISIS, " 

52 "build stereo and shape-from-shading DEMs with ISIS + ASP, and fetch Artemis III " 

53 "reference data." 

54 ), 

55 formatter_class=argparse.RawDescriptionHelpFormatter, 

56 ) 

57 parser.add_argument( 

58 "-v", 

59 "--verbose", 

60 action="store_true", 

61 help="Enable DEBUG-level logging.", 

62 ) 

63 sub = parser.add_subparsers(dest="cmd", required=True) 

64 for cmd in _COMMANDS: 

65 cmd.add_parser(sub) 

66 return parser 

67 

68 

69def main(argv: list[str] | None = None) -> int: 

70 parser = _build_parser() 

71 args = parser.parse_args(argv) 

72 

73 logging.basicConfig( 

74 level=logging.DEBUG if args.verbose else logging.INFO, 

75 format="%(asctime)s %(levelname)-8s %(message)s", 

76 datefmt="%H:%M:%S", 

77 ) 

78 

79 for cmd in _COMMANDS: 79 ↛ 83line 79 didn't jump to line 83 because the loop on line 79 didn't complete

80 if args.cmd == cmd.COMMAND: 

81 return cmd.run(args) 

82 

83 parser.print_help() 

84 return 1 

85 

86 

87if __name__ == "__main__": 87 ↛ 88line 87 didn't jump to line 88 because the condition on line 87 was never true

88 sys.exit(main())