arvados.commands.arvcli
Main executable for Arvados CLI SDK, the arv command.
This script implements the arv command’s argument parser. The arv command
is meant to be invoked in the following manner:
$ arv [--flags] subcommand|resource [...options]
where --flags are common CLI options for the various subcommands.
The ArvCLIArgumentParser class, specializing the standard Python
argparse.ArgumentParser, provides the support for this CLI usage.
1# Copyright (C) The Arvados Authors. All rights reserved. 2# 3# SPDX-License-Identifier: Apache-2.0 4 5"""Main executable for Arvados CLI SDK, the `arv` command. 6 7This script implements the `arv` command's argument parser. The `arv` command 8is meant to be invoked in the following manner: 9 10$ arv [--flags] subcommand|resource [...options] 11 12where `--flags` are common CLI options for the various subcommands. 13 14The `ArvCLIArgumentParser` class, specializing the standard Python 15`argparse.ArgumentParser`, provides the support for this CLI usage. 16""" 17 18 19import argparse 20import functools 21 22 23class ArvCLIArgumentParser(argparse.ArgumentParser): 24 """Argument parser for `arv` commands. 25 """ 26 def __init__(self, **kwargs): 27 super().__init__(description="Arvados command line client", **kwargs) 28 # Common flags to the main command. 29 self.add_argument("-n", "--dry-run", action="store_true", 30 help="Don't actually do anything") 31 self.add_argument("-v", "--verbose", action="store_true", 32 help="Print some things on stderr") 33 # Default output format is JSON, while "-s" or "--short" can be 34 # used as a shorthand for "--format=uuid". If both are specified, the 35 # last one takes effect. 36 self.add_argument( 37 "-f", "--format", 38 choices=["json", "yaml", "uuid"], 39 default="json", 40 help="Set output format" 41 ) 42 self.add_argument( 43 "-s", "--short", 44 dest="format", 45 action="store_const", const="uuid", 46 help="Return only UUIDs (equivalent to --format=uuid)" 47 ) 48 49 subparsers = self.add_subparsers( 50 dest="subcommand", 51 help="Subcommands", 52 required=True, 53 parser_class=functools.partial( 54 argparse.ArgumentParser, 55 add_help=False 56 ) 57 ) 58 59 keep_parser = subparsers.add_parser("keep") 60 keep_parser.add_argument( 61 "method", 62 choices=["ls", "get", "put", "docker"] 63 ) 64 65 ws_parser = subparsers.add_parser("ws") 66 copy_parser = subparsers.add_parser("copy") 67 68 69def dispatch(arguments=None): 70 import sys 71 72 cmd_parser = ArvCLIArgumentParser() 73 args, remaining_args = cmd_parser.parse_known_args(arguments) 74 75 match args.subcommand: 76 case "keep": 77 match args.method: 78 case "ls": 79 from arvados.commands.ls import main 80 case "get": 81 from arvados.commands.get import main 82 case "put": 83 from arvados.commands.put import main 84 case "docker": 85 from arvados.commands.keepdocker import main 86 case "ws": 87 from arvados.commands.ws import main 88 case "copy": 89 from arvados.commands.arv_copy import main 90 case _: 91 cmd_parser.error(f"unknown subcommand {args.subcommand!r}") 92 sys.exit(main(remaining_args)) 93 94 95if __name__ == "__main__": 96 dispatch()
class
ArvCLIArgumentParser(argparse.ArgumentParser):
24class ArvCLIArgumentParser(argparse.ArgumentParser): 25 """Argument parser for `arv` commands. 26 """ 27 def __init__(self, **kwargs): 28 super().__init__(description="Arvados command line client", **kwargs) 29 # Common flags to the main command. 30 self.add_argument("-n", "--dry-run", action="store_true", 31 help="Don't actually do anything") 32 self.add_argument("-v", "--verbose", action="store_true", 33 help="Print some things on stderr") 34 # Default output format is JSON, while "-s" or "--short" can be 35 # used as a shorthand for "--format=uuid". If both are specified, the 36 # last one takes effect. 37 self.add_argument( 38 "-f", "--format", 39 choices=["json", "yaml", "uuid"], 40 default="json", 41 help="Set output format" 42 ) 43 self.add_argument( 44 "-s", "--short", 45 dest="format", 46 action="store_const", const="uuid", 47 help="Return only UUIDs (equivalent to --format=uuid)" 48 ) 49 50 subparsers = self.add_subparsers( 51 dest="subcommand", 52 help="Subcommands", 53 required=True, 54 parser_class=functools.partial( 55 argparse.ArgumentParser, 56 add_help=False 57 ) 58 ) 59 60 keep_parser = subparsers.add_parser("keep") 61 keep_parser.add_argument( 62 "method", 63 choices=["ls", "get", "put", "docker"] 64 ) 65 66 ws_parser = subparsers.add_parser("ws") 67 copy_parser = subparsers.add_parser("copy")
Argument parser for arv commands.
ArvCLIArgumentParser(**kwargs)
27 def __init__(self, **kwargs): 28 super().__init__(description="Arvados command line client", **kwargs) 29 # Common flags to the main command. 30 self.add_argument("-n", "--dry-run", action="store_true", 31 help="Don't actually do anything") 32 self.add_argument("-v", "--verbose", action="store_true", 33 help="Print some things on stderr") 34 # Default output format is JSON, while "-s" or "--short" can be 35 # used as a shorthand for "--format=uuid". If both are specified, the 36 # last one takes effect. 37 self.add_argument( 38 "-f", "--format", 39 choices=["json", "yaml", "uuid"], 40 default="json", 41 help="Set output format" 42 ) 43 self.add_argument( 44 "-s", "--short", 45 dest="format", 46 action="store_const", const="uuid", 47 help="Return only UUIDs (equivalent to --format=uuid)" 48 ) 49 50 subparsers = self.add_subparsers( 51 dest="subcommand", 52 help="Subcommands", 53 required=True, 54 parser_class=functools.partial( 55 argparse.ArgumentParser, 56 add_help=False 57 ) 58 ) 59 60 keep_parser = subparsers.add_parser("keep") 61 keep_parser.add_argument( 62 "method", 63 choices=["ls", "get", "put", "docker"] 64 ) 65 66 ws_parser = subparsers.add_parser("ws") 67 copy_parser = subparsers.add_parser("copy")
def
dispatch(arguments=None):
70def dispatch(arguments=None): 71 import sys 72 73 cmd_parser = ArvCLIArgumentParser() 74 args, remaining_args = cmd_parser.parse_known_args(arguments) 75 76 match args.subcommand: 77 case "keep": 78 match args.method: 79 case "ls": 80 from arvados.commands.ls import main 81 case "get": 82 from arvados.commands.get import main 83 case "put": 84 from arvados.commands.put import main 85 case "docker": 86 from arvados.commands.keepdocker import main 87 case "ws": 88 from arvados.commands.ws import main 89 case "copy": 90 from arvados.commands.arv_copy import main 91 case _: 92 cmd_parser.error(f"unknown subcommand {args.subcommand!r}") 93 sys.exit(main(remaining_args))