Coverage for compiler_admin / commands / ls / groups.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-28 05:48 +0000

1import click 

2import pandas as pd 

3 

4from compiler_admin import FORMATS, Format 

5from compiler_admin.services import files 

6from compiler_admin.services.google import GoogleGroups 

7from compiler_admin.services.toggl import TogglUsers 

8 

9 

10def google(format: int = Format.BASIC, **kwargs): 

11 """Use GAM to print the groups in the Google Workspace.""" 

12 output = GoogleGroups().get(format=format, **kwargs) 

13 click.echo(output) 

14 

15 

16def toggl(format: int = Format.BASIC, **kwargs): 

17 """Use the Toggl API to get a list of groups. 

18 

19 Mirrors the GAM output style for Google groups. 

20 """ 

21 api = TogglUsers() 

22 

23 click.echo("Getting all Toggl groups...", err=True) 

24 groups = api.get_organization_groups() 

25 groups_df = pd.DataFrame(groups) 

26 click.echo(f"Got {len(groups)} Groups", err=True) 

27 

28 stdout = click.get_text_stream("stdout") 

29 if format in [Format.BASIC, Format.CSV]: 

30 files.write_csv(stdout, groups_df, columns=["group_id", "name", "at"]) 

31 elif format == Format.JSON: 

32 files.write_json(stdout, groups) 

33 

34 

35GROUP_SYSTEMS = {"google": google, "toggl": toggl} 

36 

37 

38@click.command() 

39@click.option( 

40 "--format", 

41 "format_key", 

42 help="The format of the output.", 

43 type=click.Choice(FORMATS.keys(), case_sensitive=False), 

44 default="basic", 

45) 

46@click.argument( 

47 "system", 

48 type=click.Choice(GROUP_SYSTEMS.keys(), case_sensitive=False), 

49 default="google", 

50) 

51def groups(system: str, format_key: str, **kwargs): 

52 """List groups in the Compiler workspace.""" 

53 format = FORMATS.get(format_key) 

54 

55 ls_system = GROUP_SYSTEMS.get(system) 

56 ls_system(format=format, **kwargs)