Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# (c) Stefan Countryman, 2019 

2 

3""" 

4Set flags for an event directory from the command line. Only flags specified 

5with ``--flags`` will be changed. To print current flags without changing 

6values, provide ``--flags`` with no arguments. 

7""" 

8 

9from textwrap import indent 

10from llama.flags import FlagDict, flag_table 

11from llama.flags.cli import Parsers as FlagParsers 

12from llama.run import Parsers as RunParsers 

13from llama.cli import CliParser 

14 

15 

16def get_parser(): 

17 """Get CLI parser.""" 

18 return CliParser(prog="llama flags", description=__doc__, 

19 parents=(RunParsers().eventfiltering, FlagParsers.flags,)) 

20 

21 

22def main(): 

23 """Set flags via CLI.""" 

24 parser = get_parser() 

25 args = parser.parse_args() 

26 for run in args.run: 

27 for event in run.events: 

28 flags = FlagDict(event.eventdir) 

29 if args.flags: 

30 table = lambda f: indent(flag_table(flags, 

31 emphasize=args.flags), 

32 8*' ')[8:] 

33 print(f"Modifying flags: {event.eventdir}\n") 

34 print(f" PRE: {table(flags)}\n") 

35 flags.update(args.flags) 

36 print(f" POST: {table(flags)}\n") 

37 else: 

38 print(f"Flags for: {event.eventdir}\n") 

39 print(indent(flag_table(flags), 8*' ') + '\n') 

40 

41 

42if __name__ == "__main__": 

43 main()