mdrs-client-python/mdrsclient/__main__.py

61 lines
1.5 KiB
Python
Raw Normal View History

2023-05-01 20:00:32 +09:00
import argparse
import sys
2023-05-01 20:00:32 +09:00
from mdrsclient.commands import (
ChaclCommand,
2023-05-01 20:00:32 +09:00
ConfigCommand,
2023-07-20 11:43:07 +09:00
CpCommand,
2023-05-10 18:17:35 +09:00
DownloadCommand,
FileMetadataCommand,
LabsCommand,
LoginCommand,
LogoutCommand,
LsCommand,
MetadataCommand,
MkdirCommand,
MvCommand,
RmCommand,
UploadCommand,
WhoamiCommand,
2023-05-01 20:00:32 +09:00
)
from mdrsclient.exceptions import MDRSException
def main() -> None:
2023-05-17 14:51:19 +09:00
description = """This is a command-line program for up- and downloading files to and from MDRS based repository."""
2023-05-01 20:00:32 +09:00
parser = argparse.ArgumentParser(description=description, formatter_class=argparse.RawDescriptionHelpFormatter)
2023-05-10 18:17:35 +09:00
parsers = parser.add_subparsers(title="subcommands")
ConfigCommand.register(parsers)
LoginCommand.register(parsers)
LogoutCommand.register(parsers)
WhoamiCommand.register(parsers)
LabsCommand.register(parsers)
LsCommand.register(parsers)
MkdirCommand.register(parsers)
UploadCommand.register(parsers)
DownloadCommand.register(parsers)
MvCommand.register(parsers)
2023-07-20 11:43:07 +09:00
CpCommand.register(parsers)
2023-05-10 18:17:35 +09:00
RmCommand.register(parsers)
ChaclCommand.register(parsers)
2023-05-10 18:17:35 +09:00
MetadataCommand.register(parsers)
FileMetadataCommand.register(parsers)
2023-05-01 20:00:32 +09:00
try:
args = parser.parse_args()
if hasattr(args, "func"):
args.func(args)
else:
parser.print_help()
except MDRSException as e:
print(f"Error: {e}")
sys.exit(2)
2023-05-23 11:48:09 +09:00
except KeyboardInterrupt:
sys.exit(130)
2023-05-01 20:00:32 +09:00
if __name__ == "__main__":
main()