/ cli.py
cli.py
 1  """brane - Local OCR for text and sheet music."""
 2  
 3  import click
 4  
 5  
 6  class DefaultGroup(click.Group):
 7      """Click group that defaults to 'ocr' when no subcommand is given."""
 8  
 9      def __init__(self, *args, default_cmd="ocr", **kwargs):
10          super().__init__(*args, **kwargs)
11          self.default_cmd = default_cmd
12  
13      def parse_args(self, ctx, args):
14          if args and args[0] not in self.commands and not args[0].startswith("-"):
15              args = [self.default_cmd] + args
16          return super().parse_args(ctx, args)
17  
18  
19  @click.group(cls=DefaultGroup)
20  def main():
21      """brane - Local OCR for text and sheet music."""
22  
23  
24  from music_engine import music  # noqa: E402
25  from ocr_engine import ocr  # noqa: E402
26  
27  main.add_command(ocr)
28  main.add_command(music)