11import argparse
22import sys
3- from typing import Any , Dict , NoReturn , Optional
3+ from typing import Any , Dict , NoReturn
44
55from strictdoc import __version__
6- from strictdoc .backend .reqif .sdoc_reqif_fields import ReqIFProfile
7- from strictdoc .backend .sdoc .constants import SDocMarkup
8- from strictdoc .commands ._shared import _check_reqif_profile
96from strictdoc .commands .about_command import AboutCommand
107from strictdoc .commands .export import ExportCommand
8+ from strictdoc .commands .import_excel import ImportExcelCommand
9+ from strictdoc .commands .import_reqif import ImportReqIFCommand
1110from strictdoc .commands .manage_autouid_command import ManageAutoUIDCommand
1211from strictdoc .commands .server import ServerCommand
1312from strictdoc .commands .version_command import VersionCommand
1413
15- EXCEL_PARSERS = ["basic" ]
16-
17-
1814COMMAND_REGISTRY : Dict [str , Any ] = {
1915 "about" : AboutCommand ,
2016 "export" : ExportCommand ,
17+ "import" : {"excel" : ImportExcelCommand , "reqif" : ImportReqIFCommand },
2118 "manage" : {"auto-uid" : ManageAutoUIDCommand },
2219 "server" : ServerCommand ,
2320 "version" : VersionCommand ,
@@ -30,22 +27,6 @@ def formatter(prog: str) -> argparse.RawTextHelpFormatter:
3027 )
3128
3229
33- def _check_reqif_import_markup (markup : Optional [str ]) -> str :
34- if markup is None or markup not in SDocMarkup .ALL :
35- valid_text_markups_string = ", " .join (SDocMarkup .ALL )
36- message = f"invalid choice: '{ markup } ' (choose from { valid_text_markups_string } )"
37- raise argparse .ArgumentTypeError (message )
38- return markup
39-
40-
41- def add_config_argument (parser : argparse .ArgumentParser ) -> None :
42- parser .add_argument (
43- "--config" ,
44- type = str ,
45- help = "Path to the StrictDoc TOML config file." ,
46- )
47-
48-
4930class SDocArgumentParser (argparse .ArgumentParser ):
5031 def error (self , message : str ) -> NoReturn :
5132 self .print_usage (sys .stderr )
@@ -93,8 +74,6 @@ def build(self) -> SDocArgumentParser:
9374 )
9475 command_subparsers .required = True
9576
96- self .add_import_command (command_subparsers )
97-
9877 # Dynamically add subcommands
9978 for name , cmd in COMMAND_REGISTRY .items ():
10079 if isinstance (cmd , dict ): # command family
@@ -121,104 +100,3 @@ def build(self) -> SDocArgumentParser:
121100 cmd .add_arguments (cmd_parser )
122101
123102 return main_parser
124-
125- @staticmethod
126- def add_import_command (
127- parent_command_parser : "argparse._SubParsersAction[SDocArgumentParser]" ,
128- ) -> None :
129- command_parser_import = parent_command_parser .add_parser (
130- "import" ,
131- help = "Create StrictDoc files from other formats." ,
132- description = "Create StrictDoc files from other formats." ,
133- formatter_class = formatter ,
134- )
135- command_parser_import_subparsers = command_parser_import .add_subparsers (
136- title = "import_format" , dest = "import_format"
137- )
138- command_parser_import_subparsers .required = True
139-
140- # Command: Import -> ReqIF.
141- command_parser_import_reqif = (
142- command_parser_import_subparsers .add_parser (
143- "reqif" ,
144- help = "Create StrictDoc file from ReqIF document." ,
145- description = "Create StrictDoc file from ReqIF document." ,
146- formatter_class = formatter ,
147- )
148- )
149-
150- command_parser_import_reqif .add_argument (
151- "profile" ,
152- type = _check_reqif_profile ,
153- help = (
154- "An argument that selects the ReqIF import/export profile. "
155- f"Possible values: {{{ ', ' .join (ReqIFProfile .ALL )} }}"
156- ),
157- )
158- command_parser_import_reqif .add_argument (
159- "input_path" ,
160- type = str ,
161- help = "Path to the input ReqIF file." ,
162- )
163- command_parser_import_reqif .add_argument (
164- "output_path" ,
165- type = str ,
166- help = "Path to the output SDoc file." ,
167- )
168- command_parser_import_reqif .add_argument (
169- "--reqif-enable-mid" ,
170- default = False ,
171- action = "store_true" ,
172- help = (
173- "Controls whether StrictDoc's MID field will be mapped to ReqIF "
174- "SPEC-OBJECT's IDENTIFIER and vice versa when exporting/importing."
175- ),
176- )
177- command_parser_import_reqif .add_argument (
178- "--reqif-import-markup" ,
179- default = None ,
180- type = _check_reqif_import_markup ,
181- help = (
182- "Controls which MARKUP option the imported SDoc documents will have. "
183- "This value is RST as what StrictDoc has by default but very often "
184- "the requirements tools use the (X)HTML markup for multiline fields in "
185- "which case HTML is the best option."
186- ),
187- )
188-
189- # Command: Import -> Excel.
190- command_parser_import_excel = (
191- command_parser_import_subparsers .add_parser (
192- "excel" ,
193- help = "Create StrictDoc file from Excel document." ,
194- description = "Create StrictDoc file Excel ReqIF document." ,
195- formatter_class = formatter ,
196- )
197- )
198-
199- def check_excel_parser (parser : str ) -> str :
200- if parser not in EXCEL_PARSERS :
201- message = (
202- f"invalid choice: '{ parser } ' (choose from { EXCEL_PARSERS } )"
203- )
204- raise argparse .ArgumentTypeError (message )
205- return parser
206-
207- command_parser_import_excel .add_argument (
208- "parser" ,
209- type = check_excel_parser ,
210- help = (
211- "An argument that selects the ReqIF parser. "
212- f"Possible values: {{{ ', ' .join (EXCEL_PARSERS )} }}"
213- ),
214- )
215- command_parser_import_excel .add_argument (
216- "input_path" ,
217- type = str ,
218- help = "Path to the input ReqIF file." ,
219- )
220- command_parser_import_excel .add_argument (
221- "output_path" ,
222- type = str ,
223- help = "Path to the output SDoc file." ,
224- )
0 commit comments