Skip to content

Task Profiles Commands

CLI commands for creating and reading task profiles.

Explicit CLI commands for task profile management.

register_cli

register_cli(app: Typer, ctx_provider: Callable[[], AppContext], logger: Logger) -> None

Register task profile management commands.

Source code in qsh/plugins/task_profiles/cli.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def register_cli(
    app: typer.Typer, ctx_provider: Callable[[], AppContext], logger: logging.Logger
) -> None:
    """Register task profile management commands."""
    resource_app = typer.Typer(help="Manage task profiles.", no_args_is_help=True)

    @resource_app.command("list")
    def list_cmd(
        tenant: TenantOption = False,
        show_all: ShowAllPagesOption = False,
        page: PageOption = 0,
        size: SizeOption = None,
        sort: Annotated[
            str,
            typer.Option(
                "--sort",
                help=("Sort criteria (default: created_date,desc). " "Format: property,direction."),
            ),
        ] = DEFAULT_TASK_PROFILE_SORT_ORDER,
        output: OutputOption = None,
        wide: WideOption = False,
    ) -> None:
        """List task profiles."""
        ctx = ctx_provider()
        logger.debug(
            "Listing task profiles: tenant=%s all=%s page=%s size=%s sort=%s",
            tenant,
            show_all,
            page,
            size,
            sort,
        )

        client = TaskProfilesClient(ctx)
        if show_all:
            payload = collect_pages_payload(
                client.iter_pages(size=DEFAULT_ALL_PAGE_SIZE, sort=sort, tenant=tenant),
                serializer=_serialize_profile,
            )
        else:
            payload = page_to_payload(
                client.list_page(page=page, size=size, sort=sort, tenant=tenant),
                serializer=_serialize_profile,
            )

        render_with_optional_schema(
            payload,
            _TASK_PROFILES_LIST_SCHEMA,
            ctx=ctx,
            output=output,
            wide=wide,
        )

    @resource_app.command("get")
    def get_cmd(
        profile_id: Annotated[UUID, typer.Argument(help="Task profile ID")],
        tenant: TenantOption = False,
        output: OutputOption = None,
    ) -> None:
        """Get a task profile by UUID."""
        ctx = ctx_provider()
        logger.debug("Getting task profile: id=%s tenant=%s", profile_id, tenant)

        client = TaskProfilesClient(ctx)
        result = client.get(id=profile_id, tenant=tenant)
        render(
            _serialize_profile(result),
            output or ctx.effective_output_format,
            wrap=ctx.wrap,
        )

    @resource_app.command("create")
    def create_cmd(
        data: Annotated[
            str,
            typer.Argument(help="Profile data as JSON, @file.json, file://path, or '-' for stdin"),
        ],
        tenant: TenantOption = False,
        output: OutputOption = None,
    ) -> None:
        """Create a task profile from a free-form JSON object."""
        ctx = ctx_provider()
        logger.debug("Creating task profile: tenant=%s", tenant)

        payload = load_json_like(data)
        model = validate_model_payload(payload, TaskProfileRequest, field_name="task profile body")
        result = TaskProfilesClient(ctx).create(body=model, tenant=tenant)
        render(
            _serialize_profile(result),
            output or ctx.effective_output_format,
            wrap=ctx.wrap,
        )

    app.add_typer(resource_app, name="task-profiles")
    logger.debug("Registered task-profiles CLI commands")