|
| 1 | +"""Argparser module for the export API""" |
| 2 | + |
| 3 | +from jina.parsers.base import set_base_parser |
| 4 | +from jina.parsers.helper import _chf |
| 5 | + |
| 6 | + |
| 7 | +def set_export_parser(parser=None): |
| 8 | + """Set the parser for exporting |
| 9 | + :param parser: the parser configure |
| 10 | +
|
| 11 | + :return: the parser |
| 12 | + """ |
| 13 | + if not parser: |
| 14 | + parser = set_base_parser() |
| 15 | + |
| 16 | + spp = parser.add_subparsers( |
| 17 | + dest='export', |
| 18 | + description='use `%(prog)-8s [sub-command] --help` ' |
| 19 | + 'to get detailed information about each sub-command', |
| 20 | + required=True, |
| 21 | + ) |
| 22 | + |
| 23 | + set_export_flowchart_parser( |
| 24 | + spp.add_parser( |
| 25 | + 'flowchart', |
| 26 | + help='Export a Flow YAML file to a flowchart', |
| 27 | + formatter_class=_chf, |
| 28 | + ) |
| 29 | + ) |
| 30 | + |
| 31 | + set_export_k8s_parser( |
| 32 | + spp.add_parser( |
| 33 | + 'kubernetes', |
| 34 | + help='Export a Flow YAML file to a Kubernetes YAML bundle', |
| 35 | + formatter_class=_chf, |
| 36 | + ) |
| 37 | + ) |
| 38 | + |
| 39 | + set_export_docker_compose_parser( |
| 40 | + spp.add_parser( |
| 41 | + 'docker-compose', |
| 42 | + help='Export a Flow YAML file to a Docker Compose YAML file', |
| 43 | + formatter_class=_chf, |
| 44 | + ) |
| 45 | + ) |
| 46 | + |
| 47 | + set_export_schema_parser( |
| 48 | + spp.add_parser( |
| 49 | + 'schema', |
| 50 | + help='Export Jina Executor & Flow API to JSONSchema files', |
| 51 | + formatter_class=_chf, |
| 52 | + ) |
| 53 | + ) |
| 54 | + |
| 55 | + return parser |
| 56 | + |
| 57 | + |
| 58 | +def mixin_base_io_parser(parser): |
| 59 | + """Add basic IO parsing args |
| 60 | + :param parser: the parser configure |
| 61 | +
|
| 62 | + """ |
| 63 | + parser.add_argument( |
| 64 | + 'flowpath', type=str, metavar='INPUT', help='The input file path of a Flow YAML' |
| 65 | + ) |
| 66 | + parser.add_argument( |
| 67 | + 'outpath', |
| 68 | + type=str, |
| 69 | + metavar='OUTPUT', |
| 70 | + help='The output path', |
| 71 | + ) |
| 72 | + |
| 73 | + |
| 74 | +def set_export_docker_compose_parser(parser=None): |
| 75 | + """Set the parser for the flow chart export |
| 76 | +
|
| 77 | + :param parser: an optional existing parser to build upon |
| 78 | + :return: the parser |
| 79 | + """ |
| 80 | + if not parser: |
| 81 | + parser = set_base_parser() |
| 82 | + |
| 83 | + mixin_base_io_parser(parser) |
| 84 | + |
| 85 | + parser.add_argument( |
| 86 | + '--network_name', |
| 87 | + type=str, |
| 88 | + help='The name of the network that will be used by the deployment name.', |
| 89 | + ) |
| 90 | + return parser |
| 91 | + |
| 92 | + |
| 93 | +def set_export_k8s_parser(parser=None): |
| 94 | + """Set the parser for the flow chart export |
| 95 | +
|
| 96 | + :param parser: an optional existing parser to build upon |
| 97 | + :return: the parser |
| 98 | + """ |
| 99 | + if not parser: |
| 100 | + parser = set_base_parser() |
| 101 | + |
| 102 | + mixin_base_io_parser(parser) |
| 103 | + |
| 104 | + parser.add_argument( |
| 105 | + '--k8s-namespace', |
| 106 | + type=str, |
| 107 | + help='The name of the k8s namespace to set for the configurations. If None, the name of the Flow will be used.', |
| 108 | + ) |
| 109 | + return parser |
| 110 | + |
| 111 | + |
| 112 | +def set_export_flowchart_parser(parser=None): |
| 113 | + """Set the parser for the flow chart export |
| 114 | +
|
| 115 | + :param parser: an optional existing parser to build upon |
| 116 | + :return: the parser |
| 117 | + """ |
| 118 | + if not parser: |
| 119 | + parser = set_base_parser() |
| 120 | + |
| 121 | + mixin_base_io_parser(parser) |
| 122 | + |
| 123 | + parser.add_argument( |
| 124 | + '--vertical-layout', |
| 125 | + action='store_true', |
| 126 | + default=False, |
| 127 | + help='If set, then the flowchart is rendered vertically from top to down.', |
| 128 | + ) |
| 129 | + return parser |
| 130 | + |
| 131 | + |
| 132 | +def set_export_schema_parser(parser=None): |
| 133 | + """Set the parser for the API export |
| 134 | +
|
| 135 | + :param parser: an optional existing parser to build upon |
| 136 | + :return: the parser |
| 137 | + """ |
| 138 | + if not parser: |
| 139 | + parser = set_base_parser() |
| 140 | + |
| 141 | + parser.add_argument( |
| 142 | + '--yaml-path', |
| 143 | + type=str, |
| 144 | + nargs='*', |
| 145 | + metavar='PATH', |
| 146 | + help='The YAML file path for storing the exported API', |
| 147 | + ) |
| 148 | + parser.add_argument( |
| 149 | + '--json-path', |
| 150 | + type=str, |
| 151 | + nargs='*', |
| 152 | + metavar='PATH', |
| 153 | + help='The JSON file path for storing the exported API', |
| 154 | + ) |
| 155 | + parser.add_argument( |
| 156 | + '--schema-path', |
| 157 | + type=str, |
| 158 | + nargs='*', |
| 159 | + metavar='PATH', |
| 160 | + help='The JSONSchema file path for storing the exported API', |
| 161 | + ) |
| 162 | + return parser |
0 commit comments