1
1
from __future__ import print_function
2
2
import argparse
3
3
from flattentool import create_template , unflatten , flatten
4
+ from flattentool .input import FORMATS as INPUT_FORMATS
5
+ from flattentool .output import FORMATS as OUTPUT_FORMATS
4
6
from six import text_type
5
7
6
8
"""
@@ -28,6 +30,9 @@ def create_parser():
28
30
parser = argparse .ArgumentParser ()
29
31
subparsers = parser .add_subparsers (dest = 'subparser_name' )
30
32
33
+ output_formats = sorted (OUTPUT_FORMATS ) + ['all' ]
34
+ input_formats = sorted (INPUT_FORMATS )
35
+
31
36
parser_create_template = subparsers .add_parser (
32
37
'create-template' ,
33
38
help = 'Create a template from the given schema' )
@@ -37,7 +42,8 @@ def create_parser():
37
42
required = True )
38
43
parser_create_template .add_argument (
39
44
"-f" , "--output-format" ,
40
- help = "Type of template you want to create. Defaults to all available options" )
45
+ help = "Type of template you want to create. Defaults to all available options" ,
46
+ choices = output_formats )
41
47
parser_create_template .add_argument (
42
48
"-m" , "--main-sheet-name" ,
43
49
help = "The name of the main sheet, as seen in the first tab of the spreadsheet for example. Defaults to main" )
@@ -67,7 +73,8 @@ def create_parser():
67
73
help = "Path to a relevant schema." )
68
74
parser_flatten .add_argument (
69
75
"-f" , "--output-format" ,
70
- help = "Type of template you want to create. Defaults to all available options" )
76
+ help = "Type of template you want to create. Defaults to all available options" ,
77
+ choices = output_formats )
71
78
parser_flatten .add_argument (
72
79
"--xml" ,
73
80
action = 'store_true' ,
@@ -105,6 +112,7 @@ def create_parser():
105
112
parser_unflatten .add_argument (
106
113
"-f" , "--input-format" ,
107
114
help = "File format of input file or directory." ,
115
+ choices = input_formats ,
108
116
required = True )
109
117
parser_unflatten .add_argument (
110
118
"--xml" ,
@@ -124,7 +132,7 @@ def create_parser():
124
132
help = "Encoding of the input file(s) (only relevant for CSV). This can be any encoding recognised by Python. Defaults to utf8." )
125
133
parser_unflatten .add_argument (
126
134
"-o" , "--output-name" ,
127
- help = "Name of the outputted file. Will have an extension appended as appropriate. Defaults to unflattened.json " )
135
+ help = "Name of the outputted file. Will have an extension appended as appropriate." )
128
136
parser_unflatten .add_argument (
129
137
"-c" , "--cell-source-map" ,
130
138
help = "Path to write a cell source map to. Will have an extension appended as appropriate." )
0 commit comments