@@ -299,5 +299,53 @@ def test_batch_records_get_not_flagged(self):
299299 self .assertFalse (any ("records.get" in f for f in findings ))
300300
301301
302+ # ---------------------------------------------------------------------------
303+ # CLI: --help / -h handling
304+ # ---------------------------------------------------------------------------
305+
306+
307+ @_skip_no_libcst
308+ class TestMainHelp (unittest .TestCase ):
309+ """``main()`` returns 0 and prints usage when --help / -h is passed.
310+
311+ Regression guard for the UX gap where ``--help`` was treated as a positional
312+ path argument and produced ``[WARN] Not a file or directory: --help``.
313+ """
314+
315+ def _run_main_capture (self , argv ):
316+ import io
317+ import contextlib
318+ from PowerPlatform .Dataverse .migration .migrate_v0_to_v1 import main
319+
320+ buf = io .StringIO ()
321+ with contextlib .redirect_stdout (buf ):
322+ rc = main (argv )
323+ return rc , buf .getvalue ()
324+
325+ def test_long_help_flag_returns_zero (self ):
326+ rc , _ = self ._run_main_capture (["--help" ])
327+ self .assertEqual (rc , 0 )
328+
329+ def test_short_help_flag_returns_zero (self ):
330+ rc , _ = self ._run_main_capture (["-h" ])
331+ self .assertEqual (rc , 0 )
332+
333+ def test_help_prints_usage_line (self ):
334+ _ , out = self ._run_main_capture (["--help" ])
335+ self .assertIn ("Usage:" , out )
336+ self .assertIn ("dataverse-migrate" , out )
337+
338+ def test_help_takes_precedence_over_other_flags (self ):
339+ """--help with other flags still exits 0 without processing paths."""
340+ rc , _ = self ._run_main_capture (["--dry-run" , "--help" , "/nonexistent/path" ])
341+ self .assertEqual (rc , 0 )
342+
343+ def test_no_args_returns_one (self ):
344+ """No arguments still prints usage but returns 1 (error)."""
345+ rc , out = self ._run_main_capture ([])
346+ self .assertEqual (rc , 1 )
347+ self .assertIn ("Usage:" , out )
348+
349+
302350if __name__ == "__main__" :
303351 unittest .main ()
0 commit comments