pyrecli 0.1.3__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyrecli-0.1.3 → pyrecli-0.2.0}/PKG-INFO +1 -1
- {pyrecli-0.1.3 → pyrecli-0.2.0}/pyproject.toml +1 -1
- pyrecli-0.2.0/pyrecli/command/slice.py +21 -0
- {pyrecli-0.1.3 → pyrecli-0.2.0}/pyrecli/pyrecli.py +22 -2
- {pyrecli-0.1.3 → pyrecli-0.2.0}/pyrecli/util.py +4 -2
- {pyrecli-0.1.3 → pyrecli-0.2.0}/LICENSE +0 -0
- {pyrecli-0.1.3 → pyrecli-0.2.0}/README.md +0 -0
- {pyrecli-0.1.3 → pyrecli-0.2.0}/pyrecli/__init__.py +0 -0
- {pyrecli-0.1.3 → pyrecli-0.2.0}/pyrecli/command/docs.py +0 -0
- {pyrecli-0.1.3 → pyrecli-0.2.0}/pyrecli/command/grabinv.py +0 -0
- {pyrecli-0.1.3 → pyrecli-0.2.0}/pyrecli/command/rename.py +0 -0
- {pyrecli-0.1.3 → pyrecli-0.2.0}/pyrecli/command/scan.py +0 -0
- {pyrecli-0.1.3 → pyrecli-0.2.0}/pyrecli/command/script.py +0 -0
- {pyrecli-0.1.3 → pyrecli-0.2.0}/pyrecli/command/send.py +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from result import Result, Err
|
|
2
|
+
from pyrecli.util import read_input_file, write_output_file, parse_templates_from_string
|
|
3
|
+
|
|
4
|
+
def slice_command(input_path: str, output_path: str, target_length: int) -> Result[None, str]:
|
|
5
|
+
input_result = read_input_file(input_path)
|
|
6
|
+
if input_result.is_err():
|
|
7
|
+
return Err(input_result.err_value)
|
|
8
|
+
|
|
9
|
+
templates_result = parse_templates_from_string(input_result.ok_value)
|
|
10
|
+
if templates_result.is_err():
|
|
11
|
+
return Err(templates_result.err_value)
|
|
12
|
+
templates = templates_result.ok_value
|
|
13
|
+
|
|
14
|
+
if not templates:
|
|
15
|
+
return Err(f'Could not find any templates in {input_path}')
|
|
16
|
+
|
|
17
|
+
first_template = templates[0]
|
|
18
|
+
sliced_templates = first_template.slice(target_length)
|
|
19
|
+
built_templates = [t.build() for t in sliced_templates]
|
|
20
|
+
|
|
21
|
+
return write_output_file(output_path, '\n'.join(built_templates))
|
|
@@ -8,6 +8,15 @@ from pyrecli.command.script import script_command
|
|
|
8
8
|
from pyrecli.command.rename import rename_command
|
|
9
9
|
from pyrecli.command.grabinv import grabinv_command
|
|
10
10
|
from pyrecli.command.docs import docs_command
|
|
11
|
+
from pyrecli.command.slice import slice_command
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def slice_target_length(value):
|
|
15
|
+
MINIMUM_LENGTH = 5
|
|
16
|
+
ivalue = int(value)
|
|
17
|
+
if ivalue < MINIMUM_LENGTH:
|
|
18
|
+
raise argparse.ArgumentTypeError(f'Target length must be at least {MINIMUM_LENGTH} codeblocks')
|
|
19
|
+
return ivalue
|
|
11
20
|
|
|
12
21
|
|
|
13
22
|
def main():
|
|
@@ -36,18 +45,23 @@ def main():
|
|
|
36
45
|
parser_rename.add_argument('var_to_rename', help='The variable to rename', type=str)
|
|
37
46
|
parser_rename.add_argument('new_var_name', help='The new name for the variable', type=str)
|
|
38
47
|
parser_rename.add_argument('--var_to_rename_scope', '-s', help='The scope to match', type=str, default=None)
|
|
39
|
-
parser_rename.add_argument('--output_path', '-o', help='The file
|
|
48
|
+
parser_rename.add_argument('--output_path', '-o', help='The file to output to', type=str, default=None)
|
|
40
49
|
|
|
41
50
|
parser_grabinv = subparsers.add_parser('grabinv', help='Save all templates in the inventory to a file with CodeClient')
|
|
42
51
|
parser_grabinv.add_argument('output_path', help='The file to output template data to', type=str)
|
|
43
52
|
|
|
44
53
|
parser_docs = subparsers.add_parser('docs', help='Generate markdown documentation from template data')
|
|
45
54
|
parser_docs.add_argument('input_path', help='The file containing template data', type=str)
|
|
46
|
-
parser_docs.add_argument('output_path', help='The file
|
|
55
|
+
parser_docs.add_argument('output_path', help='The file to output to', type=str)
|
|
47
56
|
parser_docs.add_argument('title', help='The title for the docs', type=str)
|
|
48
57
|
parser_docs.add_argument('--include_hidden', '-ih', help='Include hidden functions and processes', action='store_true')
|
|
49
58
|
parser_docs.add_argument('--notoc', help='Omit the table of contents', action='store_true')
|
|
50
59
|
|
|
60
|
+
parser_slice = subparsers.add_parser('slice', help='Slice a template into multiple smaller templates')
|
|
61
|
+
parser_slice.add_argument('input_path', help='The file containing template data', type=str)
|
|
62
|
+
parser_slice.add_argument('output_path', help='The file to output template data to', type=str)
|
|
63
|
+
parser_slice.add_argument('target_length', help='The maximum length of each sliced template', type=slice_target_length)
|
|
64
|
+
|
|
51
65
|
parsed_args = parser.parse_args()
|
|
52
66
|
|
|
53
67
|
match parsed_args.command:
|
|
@@ -81,6 +95,12 @@ def main():
|
|
|
81
95
|
parsed_args.input_path, parsed_args.output_path,
|
|
82
96
|
parsed_args.title, parsed_args.include_hidden, parsed_args.notoc
|
|
83
97
|
)
|
|
98
|
+
|
|
99
|
+
case 'slice':
|
|
100
|
+
command_result = slice_command(
|
|
101
|
+
parsed_args.input_path, parsed_args.output_path,
|
|
102
|
+
parsed_args.target_length
|
|
103
|
+
)
|
|
84
104
|
|
|
85
105
|
if command_result.is_err():
|
|
86
106
|
print(command_result.err_value)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import re
|
|
3
|
+
import sys
|
|
3
4
|
from result import Result, Ok, Err
|
|
4
5
|
import websocket
|
|
5
6
|
from dfpyre import DFTemplate
|
|
@@ -47,9 +48,10 @@ def parse_templates_from_string(templates: str) -> Result[list[DFTemplate], str]
|
|
|
47
48
|
def read_input_file(path: str) -> Result[str, str]:
|
|
48
49
|
if path == '-':
|
|
49
50
|
try:
|
|
50
|
-
input_string =
|
|
51
|
+
input_string = sys.stdin.read()
|
|
51
52
|
except EOFError:
|
|
52
|
-
|
|
53
|
+
pass
|
|
54
|
+
return Ok(input_string.strip())
|
|
53
55
|
|
|
54
56
|
if not os.path.isfile(path):
|
|
55
57
|
return Err(f'"{path}" is not a file.')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|