Skip to content

Commit

Permalink
Add command to export .stbl files
Browse files Browse the repository at this point in the history
  • Loading branch information
garrett-he committed Aug 7, 2024
1 parent db22922 commit 836de58
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/stbl/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
command_group = []
from .export import export_command

command_group = [export_command]
21 changes: 21 additions & 0 deletions src/stbl/commands/export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import json

import click

from stbl.stbl import STBLFile


@click.command('export')
@click.argument('stbl_file', type=click.Path(exists=True, dir_okay=False))
def export_command(stbl_file):
"""Export .stbl file in JSON format."""

stbl = STBLFile()
stbl.read(stbl_file)

if not stbl.validate():
raise RuntimeError(f'Invalid .stbl file format "{stbl_file}".')

data = list(map(lambda entry: {'instance': '0x' + ('%08x' % entry.instance_id).upper(), 'text': entry.text}, stbl.entries))

print(json.dumps(data, ensure_ascii=False, indent=4))

0 comments on commit 836de58

Please sign in to comment.