Skip to content

Commit c154302

Browse files
committed
🔨 Add args to schema.py
1 parent b5ccddb commit c154302

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

buildroot/share/PlatformIO/scripts/schema.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,40 @@ def main():
382382
schema = None
383383

384384
if schema:
385-
print("Generating JSON ...")
386-
dump_json(schema, Path('schema.json'))
387-
group_options(schema)
388-
dump_json(schema, Path('schema_grouped.json'))
389-
390-
try:
391-
import yaml
392-
except ImportError:
393-
print("Installing YAML module ...")
394-
import subprocess
395-
subprocess.run(['python3', '-m', 'pip', 'install', 'pyyaml'])
396-
import yaml
397-
398-
print("Generating YML ...")
399-
dump_yaml(schema, Path('schema.yml'))
385+
386+
# Get the first command line argument
387+
import sys
388+
if len(sys.argv) > 1:
389+
arg = sys.argv[1]
390+
else:
391+
arg = 'some'
392+
393+
# JSON schema
394+
if arg in ['some', 'json', 'jsons']:
395+
print("Generating JSON ...")
396+
dump_json(schema, Path('schema.json'))
397+
398+
# JSON schema (wildcard names)
399+
if arg in ['group', 'jsons']:
400+
group_options(schema)
401+
dump_json(schema, Path('schema_grouped.json'))
402+
403+
# YAML
404+
if arg in ['some', 'yml', 'yaml']:
405+
try:
406+
import yaml
407+
except ImportError:
408+
print("Installing YAML module ...")
409+
import subprocess
410+
try:
411+
subprocess.run(['python3', '-m', 'pip', 'install', 'pyyaml'])
412+
import yaml
413+
except:
414+
print("Failed to install YAML module")
415+
return
416+
417+
print("Generating YML ...")
418+
dump_yaml(schema, Path('schema.yml'))
400419

401420
if __name__ == '__main__':
402421
main()

0 commit comments

Comments
 (0)