# Unity Gaming Services CLI

> Create and manage schedule configurations from the command line using the Unity Gaming Services command-line interface.

[Unity Gaming Services CLI](https://services.docs.unity.com/guides/ugs-cli/latest/general/overview) を使用して、スケジュールを操作できます。CLI により、コマンドラインからスケジュール設定を管理できます。

## 前提条件##prerequisites

CLI の詳細情報については、[Unity Gaming Services CLI の使用の準備ガイド](https://services.docs.unity.com/guides/ugs-cli/latest/general/get-started/install-the-cli/) のステップに従います。

このガイドに従うには、最初に以下のアクションを実行する必要があります。

1. [UGS CLI をインストール](https://services.docs.unity.com/guides/ugs-cli/latest/general/get-started/install-the-cli/) します。

2. 以下を使用して、プロジェクト ID と環境を設定します。
   `ugs config set project-id <your-project-id>`
   `ugs config set environment-name <your-environment-name>`

3. [Scheduler](https://services.docs.unity.com/docs/service-account-auth/index.html#scheduler-configuration-editor) と [環境管理](https://services.docs.unity.com/docs/service-account-auth/index.html#unity-environments-admin) に必要なロールでサービスアカウントを設定します。詳細については、[認証の取得](https://services.docs.unity.com/guides/ugs-cli/latest/general/get-started/get-authenticated/) を参照してください。

## CLI の使用##using-the-cli

すべてのコマンドとオプションの完全なリファレンスについては、[Schedules コマンドラインのドキュメント](https://services.docs.unity.com/guides/ugs-cli/latest/scheduler/Scheduler%20Command%20Line/overview) を参照してください。

> **Note:**
>
> **ノート:** `ugs scheduler` コマンドは `ugs sched` としても使用可能です。

### スケジュールのデプロイ##deploy-schedules

`new-file` コマンドを実行して、スケジュール設定をローカルに作成します。

```bash
ugs scheduler new-file <file-name>
```

設定ファイルのコンテンツは以下のようになります。

```json
{
  "$schema": "https://ugs-config-schemas.unity3d.com/v1/schedules.schema.json",
  "Configs": {
    "Schedule1": {
      "EventName": "EventType1",
      "Type": "recurring",
      "Schedule": "0 * * * *",
      "PayloadVersion": 1,
      "Payload": "{}"
    },
    "Schedule2": {
      "EventName": "EventType2",
      "Type": "one-time",
      "Schedule": "2024-03-08T13:06:32.311+00:00",
      "PayloadVersion": 1,
      "Payload": "{ \"message\": \"Hello, world!\"}"
    }
  }
}
```

必要に応じて、スケジュール設定を複数のファイルに分割することもできます。

```json
{
  "$schema": "https://ugs-config-schemas.unity3d.com/v1/schedules.schema.json",
  "Configs": {
    "Schedule1": {
      "EventName": "EventType1",
      "Type": "recurring",
      "Schedule": "0 * * * *",
      "PayloadVersion": 1,
      "Payload": "{}"
    }
  }
}
```

```json
{
  "$schema": "https://ugs-config-schemas.unity3d.com/v1/schedules.schema.json",
  "Configs": {
    "Schedule2": {
      "EventName": "EventType2",
      "Type": "one-time",
      "Schedule": "2024-03-08T13:06:32.311+00:00",
      "PayloadVersion": 1,
      "Payload": "{ \"message\": \"Hello, world!\"}"
    }
  }
}
```

`Deploy` コマンドを使用して、ローカルスケジュール設定ファイルをリモート環境にプロモートできます。

アクティブなスケジュールになるように設定ファイルをデプロイする必要があります。

```bash
ugs deploy <path-to-schedules-file> <path-to-schedules-file>
```

```bash
ugs deploy <path-to-directory>
```

### スケジュールの取得##retrieve-schedules

現在アクティブなすべてのスケジュールを一覧表示するには、以下のコマンドを実行します。

```bash
ugs scheduler list
```

`Fetch` コマンドを使用して、一度に複数のスケジュールをリモートから取得できます。

指定されたパスは、スケジュールが保存されるディレクトリです。

```bash
ugs fetch <path>
```

### スケジュールの削除##delete-schedules

スケジュールを削除するには、`--reconcile` フラグを指定して `deploy` コマンドを実行します。

> **Warning:**
>
> リコンサイルは破壊的な操作です。指定されたパスに存在しないすべてのスケジュールが削除されます。`--dry-run` フラグを使用してコマンドの出力を確認してから、フラグなしでコマンドを実行できます。

```bash
ugs deploy --services scheduler <path-to-config-file> --reconcile
```
