From 53ba65eb59d0bced37e73d8bf96a0d7a7285f662 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 7 Jan 2022 15:29:27 -0500 Subject: QPDFArgParser: handle optional choices including help Handle optional choices in addition to required choices. Refactor the way help options are added to completion to make it work with optional help choices. --- generate_auto_job | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'generate_auto_job') diff --git a/generate_auto_job b/generate_auto_job index 7e70d29c..2dc51105 100755 --- a/generate_auto_job +++ b/generate_auto_job @@ -119,7 +119,7 @@ class Main: self.check_keys('top', o, set( ['table', 'prefix', 'bare', 'positional', 'optional_parameter', 'required_parameter', - 'required_choices', 'from_table'])) + 'required_choices', 'optional_choices', 'from_table'])) def to_identifier(self, label, prefix, const): identifier = re.sub(r'[^a-zA-Z0-9]', '_', label) @@ -157,6 +157,9 @@ class Main: for i in o.get('required_choices', {}): identifier = self.to_identifier(i, prefix, False) print(f'void {identifier}(char *);', file=f) + for i in o.get('optional_choices', {}): + identifier = self.to_identifier(i, prefix, False) + print(f'void {identifier}(char *);', file=f) if table not in ('main', 'help'): identifier = self.to_identifier(table, 'argEnd', False) print(f'void {identifier}();', file=f) @@ -204,9 +207,14 @@ class Main: f', "{v}");', file=f) for k, v in o.get('required_choices', {}).items(): identifier = self.to_identifier(k, prefix, False) - print(f'this->ap.addRequiredChoices("{k}", ' + print(f'this->ap.addChoices("{k}", ' + f'p(&ArgParser::{identifier})' + f', true, {v}_choices);', file=f) + for k, v in o.get('optional_choices', {}).items(): + identifier = self.to_identifier(k, prefix, False) + print(f'this->ap.addChoices("{k}", ' f'p(&ArgParser::{identifier})' - f', {v}_choices);', file=f) + f', false, {v}_choices);', file=f) for o in data['options']: table = o['table'] if 'from_table' not in o: -- cgit v1.2.3-54-g00ecf