Commit b8c58bb3 authored by Lucas Bourneuf's avatar Lucas Bourneuf

CLI can read clingo output directly as stdin

parent 2509ea7a
......@@ -6,9 +6,12 @@ file instead of the direct enumeration of filenames.
"""
import os
import sys
import argparse
import itertools
import clyngor
from . import core
from . import module_loader
from . import __version__
......@@ -32,8 +35,10 @@ def parse_cli(args:iter=None) -> dict:
parser.add_argument('--version', action='version', version=f'biseau {__version__}')
# flags
parser.add_argument('--gif', '-g', action='store_true', default=None,
parser.add_argument('--gif', '-g', action='store_true', default=False,
help="Do not merge graphs ; build a gif with frame for each model")
parser.add_argument('--stdin', action='store_true', default=False,
help="Take input in stdin, reading it as clingo output, where each model is a script added to the script pool")
return parser.parse_args(args)
......@@ -48,6 +53,12 @@ if __name__ == '__main__':
)
if os.path.splitext(args.outfile)[1] == '.gif' and args.gif is None:
args.gif = True # turn on the gif behavior
if args.stdin: # expect clingo output in stdin
stdin_scripts = []
for atoms in clyngor.utils.parse_clingo_output(sys.stdin):
atoms = clyngor.utils.answer_set_to_str(atoms, atom_end='.', atom_sep='\n')
stdin_scripts.extend(module_loader.build_scripts_from_asp_code(atoms))
all_infiles = itertools.chain(all_infiles, stdin_scripts)
if args.gif:
core.gif_from_filenames(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment