@@ -61,12 +61,17 @@ def write_cl(string, output_file):
61
61
if __name__ == "__main__" :
62
62
# Arg Parsing
63
63
parser = argparse .ArgumentParser ()
64
+ # File in
64
65
parser .add_argument ("-file" , nargs = '?' , required = True )
66
+ # Boolean if the file is a tex file
65
67
parser .add_argument ("-tex" , nargs = '?' , default = False , required = False )
68
+ # Replace with other file
69
+ parser .add_argument ("-fileinclude" , nargs = '?' , default = False , required = False )
66
70
args = parser .parse_known_args ()[0 ]
67
71
68
72
# Read in template file
69
73
tex = args .tex
74
+ fileinclude = args .fileinclude
70
75
filename = args .file
71
76
file = get_file (filename )
72
77
if file == 1 :
@@ -77,17 +82,32 @@ def write_cl(string, output_file):
77
82
78
83
# Find all template entries
79
84
entries = re .findall ("{{(.*?)}}" , file )
85
+
86
+ # For each placeholder
80
87
for entry in entries :
88
+ # Check for a set argument
81
89
parser .add_argument ("-%s" % entry , nargs = '?' , default = "UNSET" )
82
90
args = vars (parser .parse_known_args ()[0 ])
83
- if args [entry ] == "UNSET" or args [entry ] == None :
84
- file = file .sub ("{{%s}}" % entry , input (info ("Enter value for '%s': " % entry )))
85
- else :
86
- file = file .sub ("{{%s}}" % entry , args [entry ])
87
91
92
+ if fileinclude :
93
+ # When file include is enabled check for a file with the placeholder name
94
+ fileincludename = "./includes/{}" .format (entry )
95
+ substitute = get_file (fileincludename )
96
+
97
+ while substitute == 1 :
98
+ fileincludename = input (info ("'%s' could not be found. Enter an alternative file and path from %s: " % (entry , os .getcwd ())))
99
+ substitute = get_file (fileincludename )
100
+
101
+ file = file .sub ("{{%s}}" % entry , substitute )
102
+
103
+ else :
104
+ if args [entry ] == "UNSET" or args [entry ] == None :
105
+ file = file .sub ("{{%s}}" % entry , input (info ("Enter value for '%s': " % entry )))
106
+ else :
107
+ file = file .sub ("{{%s}}" % entry , args [entry ])
88
108
89
109
# Write output
90
- if "." in filename :
110
+ if "." in filename :
91
111
filename = filename .split ("." )[0 ]
92
112
parser .add_argument ("-outfile" , nargs = '?' , default = "%s_out" % filename )
93
113
write_cl (file , parser .parse_known_args ()[0 ].outfile )
@@ -100,7 +120,5 @@ def write_cl(string, output_file):
100
120
print (success ("\n Finished writing cover letter.\n " ))
101
121
print (file )
102
122
103
-
104
-
105
123
# All done
106
124
exit (0 )
0 commit comments