# Profile 管理

> Shoplazza CLI 的 profile 命令：为每个店铺添加 Profile、列出和查看 Profile、切换当前 Profile、修改其作用域、重命名或删除。

管理店铺 Profile。Profile 是已登录账户下按店铺划分的执行上下文（店铺、店铺令牌和作用域），让你无需重新认证即可操作多个店铺。[`auth login --store-domain`](./auth#login) 和 [`auth store use`](./auth#store-use) 会自动创建并切换 Profile。

如需让单条命令使用另一个 Profile 而不切换，传入全局参数 `--profile <名称>` 或设置 `SHOPLAZZA_CLI_PROFILE`。`--profile` 优先于环境变量，环境变量优先于当前 Profile。

在交互式终端中，`add` 会询问缺少的名称和店铺，`use`、`rename`、`remove` 可从列表中选择 Profile，`remove` 还会请你确认。

## add

添加一个绑定到店铺的命名 Profile，并申请、缓存其店铺令牌。需要先登录账户（`shoplazza auth login`）。

```shell
shoplazza profile add [参数]
```

### 参数

| 参数 | 类型 | 说明 |
|------|------|------|
| `--name <名称>` | string | Profile 名称（必填） |
| `--store-domain, -s <域名>` | string | 该 Profile 绑定的店铺域名（如 `my-store.myshoplaza.com`）（必填） |
| `--scope <作用域>` | StringSlice | 该 Profile 的作用域（须为账户已授权作用域的子集）；留空则授予账户的全部作用域 |
| `--use` | bool | 添加后设为当前 Profile |

### 示例

```shell
# 为店铺添加 Profile
shoplazza profile add --name prod --store-domain my-store.myshoplaza.com

# 添加限定作用域的 Profile 并切换过去
shoplazza profile add --name staging --store-domain staging.myshoplaza.com --scope read_product --use
```

## list

列出所有已配置的 Profile，包括店铺、作用域、令牌状态以及哪个是当前 Profile。

```shell
shoplazza profile list
```

## info

显示某个 Profile 的详情（默认当前 Profile）。

```shell
shoplazza profile info [参数]
```

### 参数

| 参数 | 类型 | 说明 |
|------|------|------|
| `--name <名称>` | string | 要查看的 Profile（默认当前 Profile） |

## use

切换到指定的 Profile，或切回上一个 Profile。

```shell
shoplazza profile use [参数]
```

### 参数

| 参数 | 类型 | 说明 |
|------|------|------|
| `--name <名称>` | string | 要切换到的 Profile |
| `--previous` | bool | 切回上一个 Profile |

### 示例

```shell
# 切换到指定 Profile
shoplazza profile use --name prod

# 切回上一个 Profile
shoplazza profile use --previous

# 单条命令使用另一个 Profile，不切换
shoplazza products list --profile prod
```

## update

更新某个 Profile 的作用域。缓存的店铺令牌会被丢弃，下一条命令按新作用域重新申请。

```shell
shoplazza profile update [参数]
```

### 参数

| 参数 | 类型 | 说明 |
|------|------|------|
| `--name <名称>` | string | 要更新的 Profile（默认当前 Profile） |
| `--scope <作用域>` | StringSlice | 该 Profile 的新作用域（须为账户已授权作用域的子集） |

## rename

重命名 Profile。

```shell
shoplazza profile rename [参数]
```

### 参数

| 参数 | 类型 | 说明 |
|------|------|------|
| `--from <名称>` | string | 现有 Profile 名称（默认当前 Profile） |
| `--to <名称>` | string | 新的 Profile 名称（必填） |

## remove

删除 Profile：包括其缓存的店铺令牌和配置记录。账户登录状态保留。

```shell
shoplazza profile remove [参数]
```

### 参数

| 参数 | 类型 | 说明 |
|------|------|------|
| `--name <名称>` | string | 要删除的 Profile（必填） |
