@@ -645,7 +645,7 @@ def save_next(self):
645645tests_run = 0
646646
647647class TestParserPasses (unittest .TestCase ):
648- directory = "blurb/ tests/pass"
648+ directory = "tests/pass"
649649
650650 def filename_test (self , filename ):
651651 b = Blurbs ()
@@ -670,7 +670,7 @@ def test_files(self):
670670
671671
672672class TestParserFailures (TestParserPasses ):
673- directory = "blurb/ tests/fail"
673+ directory = "tests/fail"
674674
675675 def filename_test (self , filename ):
676676 b = Blurbs ()
@@ -745,6 +745,13 @@ def get_subcommand(subcommand):
745745
746746
747747
748+ @subcommand
749+ def version ():
750+ """Print blurb version."""
751+ print ("blurb version" , __version__ )
752+
753+
754+
748755@subcommand
749756def help (subcommand = None ):
750757 """
@@ -826,8 +833,19 @@ def help(subcommand=None):
826833 print (doc )
827834 sys .exit (0 )
828835
829- # Make "blurb --help" work.
836+ # Make "blurb --help/--version/-V " work.
830837subcommands ["--help" ] = help
838+ subcommands ["--version" ] = version
839+ subcommands ["-V" ] = version
840+
841+
842+ def _find_blurb_dir ():
843+ if os .path .isdir ("blurb" ):
844+ return "blurb"
845+ for path in glob .iglob ("blurb-*" ):
846+ if os .path .isdir (path ):
847+ return path
848+ return None
831849
832850
833851@subcommand
@@ -838,12 +856,13 @@ def test(*args):
838856 # unittest.main doesn't work because this isn't a module
839857 # so we'll do it ourselves
840858
841- while not os . path . isdir ( "blurb" ) :
859+ while ( blurb_dir := _find_blurb_dir ()) is None :
842860 old_dir = os .getcwd ()
843861 os .chdir (".." )
844862 if old_dir == os .getcwd ():
845863 # we reached the root and never found it!
846864 sys .exit ("Error: Couldn't find the root of your blurb repo!" )
865+ os .chdir (blurb_dir )
847866
848867 print ("-" * 79 )
849868
@@ -1379,7 +1398,7 @@ def main():
13791398 fn = get_subcommand (subcommand )
13801399
13811400 # hack
1382- if fn in (test , help ):
1401+ if fn in (help , test , version ):
13831402 sys .exit (fn (* args ))
13841403
13851404 try :
0 commit comments