# Path: src/stratis_cli/_error_reporting.py
# def handle_error(err):
#     """
#     Do the right thing with the given error, which may be the head of an error
#     chain.
# 
#     :param Exception err: an exception
#     """
# 
#     errors = list(get_errors(err))
# 
#     explanation = _interpret_errors(errors)
# 
#     # The goal is to have an explanation for every error chain. If there is
#     # none, then this will rapidly be fixed, so it will be difficult to
#     # maintain coverage for this branch.
#     if explanation is None:  # pragma: no cover
#         exit_msg = (
#             "stratis encountered an unexpected error during execution. "
#             "Please report the error and include in your report the stack "
#             "trace shown below."
#         )
#         print(exit_msg, os.linesep, file=sys.stderr, flush=True)
#         raise err
# 
#     exit_msg = "Execution failed:%s%s" % (os.linesep, explanation)
#     exit_(StratisCliErrorCodes.ERROR, exit_msg)
# 
# Path: src/stratis_cli/_errors.py
# class StratisCliActionError(StratisCliRuntimeError):
#     """
#     Raised if an action selected by the parser failed.
#     """
# 
#     def __init__(self, command_line_args, namespace):
#         """
#         Initialize with parser-returned namespace.
# 
#         :param command_line_args: the arguments passed on the command line
#         :type command_line_args: list of str
#         :param Namespace namespace: the namespace constructed by the parser
#         """
#         # pylint: disable=super-init-not-called
#         self.command_line_args = command_line_args
#         self.namespace = namespace
# 
#     def __str__(self):
#         fmt_str = (
#             "Action selected by command-line arguments %s which were "
#             "parsed to %s failed"
#         )
#         return fmt_str % (self.command_line_args, self.namespace)
# 
# class StratisCliEnvironmentError(StratisCliError):
#     """
#     Exception that occurs during processing of environment variables.
#     """
# 
# Path: src/stratis_cli/_parser/_parser.py
# def gen_parser():
#     """
#     Make the parser.
# 
#     :returns: a fully constructed parser for command-line arguments
#     :rtype: ArgumentParser
#     """
#     parser = argparse.ArgumentParser(
#         description="Stratis Storage Manager", prog="stratis"
#     )
# 
#     # version is special, it has explicit support in argparse
#     parser.add_argument("--version", action="version", version=__version__)
# 
#     _add_args(parser, GEN_ARGS)
# 
#     subparsers = parser.add_subparsers(title="subcommands")
# 
#     for subcmd in ROOT_SUBCOMMANDS:
#         add_subcommand(subparsers, subcmd)
# 
#     parser.set_defaults(func=PRINT_HELP(parser))
# 
#     return parser


import justbytes as jb
from ._error_reporting import handle_error
from ._errors import StratisCliActionError, StratisCliEnvironmentError
from ._parser import gen_parser
    parser = gen_parser()

    # Set default configuration parameters for display of sizes, i.e., values
    # that are generally given in bytes or some multiple thereof.
    jb.Config.set_display_config(jb.DisplayConfig(show_approx_str=False))

    def the_func(command_line_args):
        """
        Run according to the arguments passed.
        """
        result = parser.parse_args(command_line_args)
        try:
            try:
                result.func(result)

            # Keyboard Interrupt is recaught at the outermost possible layer.
            # It is outside the regular execution of the program, so it is
            # handled only there; it is just reraised here.
            # The same holds for SystemExit, except that it must be allowed
            # to propagate to the interpreter, i.e., it should not be recaught
            # anywhere.
            except (
                BrokenPipeError,
                KeyboardInterrupt,
                SystemExit,
                StratisCliEnvironmentError,
            ) as err:
                raise err
            except BaseException as err:
                raise StratisCliActionError(command_line_args, result) from err

# Path: src/stratis_cli/_error_reporting.py
# def handle_error(err):
#     """
#     Do the right thing with the given error, which may be the head of an error
#     chain.
# 
#     :param Exception err: an exception
#     """
# 
#     errors = list(get_errors(err))
# 
#     explanation = _interpret_errors(errors)
# 
#     # The goal is to have an explanation for every error chain. If there is
#     # none, then this will rapidly be fixed, so it will be difficult to
#     # maintain coverage for this branch.
#     if explanation is None:  # pragma: no cover
#         exit_msg = (
#             "stratis encountered an unexpected error during execution. "
#             "Please report the error and include in your report the stack "
#             "trace shown below."
#         )
#         print(exit_msg, os.linesep, file=sys.stderr, flush=True)
#         raise err
# 
#     exit_msg = "Execution failed:%s%s" % (os.linesep, explanation)
#     exit_(StratisCliErrorCodes.ERROR, exit_msg)
# 
# Path: src/stratis_cli/_errors.py
# class StratisCliActionError(StratisCliRuntimeError):
#     """
#     Raised if an action selected by the parser failed.
#     """
# 
#     def __init__(self, command_line_args, namespace):
#         """
#         Initialize with parser-returned namespace.
# 
#         :param command_line_args: the arguments passed on the command line
#         :type command_line_args: list of str
#         :param Namespace namespace: the namespace constructed by the parser
#         """
#         # pylint: disable=super-init-not-called
#         self.command_line_args = command_line_args
#         self.namespace = namespace
# 
#     def __str__(self):
#         fmt_str = (
#             "Action selected by command-line arguments %s which were "
#             "parsed to %s failed"
#         )
#         return fmt_str % (self.command_line_args, self.namespace)
# 
# class StratisCliEnvironmentError(StratisCliError):
#     """
#     Exception that occurs during processing of environment variables.
#     """
# 
# Path: src/stratis_cli/_parser/_parser.py
# def gen_parser():
#     """
#     Make the parser.
# 
#     :returns: a fully constructed parser for command-line arguments
#     :rtype: ArgumentParser
#     """
#     parser = argparse.ArgumentParser(
#         description="Stratis Storage Manager", prog="stratis"
#     )
# 
#     # version is special, it has explicit support in argparse
#     parser.add_argument("--version", action="version", version=__version__)
# 
#     _add_args(parser, GEN_ARGS)
# 
#     subparsers = parser.add_subparsers(title="subcommands")
# 
#     for subcmd in ROOT_SUBCOMMANDS:
#         add_subcommand(subparsers, subcmd)
# 
#     parser.set_defaults(func=PRINT_HELP(parser))
# 
#     return parser


# Path: src/stratis_cli/_main.py
import justbytes as jb
from ._error_reporting import handle_error
from ._errors import StratisCliActionError, StratisCliEnvironmentError
from ._parser import gen_parser

    parser = gen_parser()

    # Set default configuration parameters for display of sizes, i.e., values
    # that are generally given in bytes or some multiple thereof.
    jb.Config.set_display_config(jb.DisplayConfig(show_approx_str=False))

    def the_func(command_line_args):
        """
        Run according to the arguments passed.
        """
        result = parser.parse_args(command_line_args)
        try:
            try:
                result.func(result)

            # Keyboard Interrupt is recaught at the outermost possible layer.
            # It is outside the regular execution of the program, so it is
            # handled only there; it is just reraised here.
            # The same holds for SystemExit, except that it must be allowed
            # to propagate to the interpreter, i.e., it should not be recaught
            # anywhere.
            except (
                BrokenPipeError,
                KeyboardInterrupt,
                SystemExit,
                StratisCliEnvironmentError,
            ) as err:
                raise err
            except BaseException as err:
                raise StratisCliActionError(command_line_args, result) from err

        except StratisCliActionError as err: