Browse Source

Allows for multiple input files

master
sloum 10 months ago
parent
commit
aa07ad4254
2 changed files with 32 additions and 15 deletions
  1. +3
    -0
      .gitignore
  2. +29
    -15
      recipe

+ 3
- 0
.gitignore View File

@ -0,0 +1,3 @@
*.html
*.gmi
*.txt

+ 29
- 15
recipe View File

@ -296,13 +296,13 @@ def print_help():
help_text = '''recipe v0.5
Usage:
recipe [flags] [rcp-file]
recipe [flag...] [rcp-filepath...]
Flags:
-H, --HTML Output html
-m, --markdown Output markdown
-t, --text Output plain text
-G, --gemini Output text/gemini
-g, --gemini Output text/gemini
-s, --stdout Print the output to stdout instead of a file
-h, --help Print help and exit'''
print(help_text, file=sys.stderr)
@ -312,24 +312,38 @@ def parse_args():
args = sys.argv[1:]
if not len(args) or '-h' in args or '--help' in args:
print_help()
path = args.pop()
process_file(path)
files = []
arg_list = []
if '-s' in args or '--stdout' in args:
global print_to_stdout
print_to_stdout = True
for arg in args:
if arg in ['-H', '--HTML', '--html']:
output_html(path,)
elif arg in ['-m', '--MD', '--md', '--markdown']:
output_markdown(path)
elif arg in ['-t', '--text', '--txt', '--plain']:
output_plaintext(path)
elif arg in ['-G', '--gemini', '--gmi']:
output_gemini(path)
elif arg in ['-s', '--stdout']:
continue
if not arg or arg[0] == '-':
arg_list.append(arg)
else:
print("Unknown flag: {}".format(arg), file=sys.stderr)
files.append(arg)
for ind, path in enumerate(files):
global recipe
print("{} of {}: {}".format(ind+1, len(files), path), file=sys.stderr)
recipe = {'meta': {}, 'ingredients': [], 'instructions': [], 'notes': [], 'intro_text': []}
process_file(path)
for arg in arg_list:
if arg in ['-H', '--HTML', '--html']:
output_html(path)
elif arg in ['-m', '--MD', '--md', '--markdown']:
output_markdown(path)
elif arg in ['-t', '--text', '--txt', '--plain']:
output_plaintext(path)
elif arg in ['-g', '--gemini', '--gmi']:
output_gemini(path)
elif arg in ['-s', '--stdout']:
continue
else:
print("Unknown flag: {}".format(arg), file=sys.stderr)
if __name__ == '__main__':
parse_args()


Loading…
Cancel
Save