1"""ll-issues check-flag: Exit 0 if a boolean frontmatter field equals 'true'."""

2

3 from __future__ import annotations

4

5 import argparse

6 import sys

7 from typing import TYPE_CHECKING

8

9 if TYPE_CHECKING:

10 from little_loops.config import BRConfig

11

12

13 def cmd_check_flag(config: BRConfig, args: argparse.Namespace) -> int:

14 """Exit 0 if the named frontmatter field on the issue equals 'true'.

15

16 Args:

17 config: Project configuration

18 args: Parsed arguments with .issue_id and .field

19

20 Returns:

21 0 if the field is 'true', 1 otherwise

22 """

23 from little_loops.cli.issues.show import _resolve_issue_id

24 from little_loops.frontmatter import parse_frontmatter

25

26 path = _resolve_issue_id(config, args.issue_id)

27 if path is None:

28 print(f"Error: Issue '{args.issue_id}' not found.", file=sys.stderr)

29 return 1

30

31 fm = parse_frontmatter(path.read_text(), coerce_types=True)

32 value = fm.get(args.field)

33 return 0 if str(value).lower() == "true" else 1