diff --git a/bittensor/cli.py b/bittensor/cli.py index b0e16f9f75..a8d51fe40c 100644 --- a/bittensor/cli.py +++ b/bittensor/cli.py @@ -135,6 +135,20 @@ } +class CLIErrorParser(argparse.ArgumentParser): + """ + Custom ArgumentParser for better error messages. + """ + + def error(self, message): + """ + This method is called when an error occurs. It prints a custom error message. + """ + sys.stderr.write(f"Error: {message}\n") + self.print_help() + sys.exit(2) + + class cli: """ Implementation of the Command Line Interface (CLI) class for the Bittensor protocol. @@ -191,7 +205,7 @@ def __create_parser__() -> "argparse.ArgumentParser": argparse.ArgumentParser: An argument parser object for Bittensor CLI. """ # Define the basic argument parser. - parser = argparse.ArgumentParser( + parser = CLIErrorParser( description=f"bittensor cli v{bittensor.__version__}", usage="btcli ", add_help=True,