# Walkthrough guide for Gate Management with CLI

{% callout type="info" %}
This guide assumes you have Statsig CLI installed and configured with the required API keys. Refer to the [Statsig CLI Overview](https://docs.statsig.com/statsigcli/introduction) to get started.
{% /callout %}

## Create a new gate

Create a new empty gate with no rules using the `create` command on gates.

```bash
$ siggy gates create my-first-gate

# Response
{
  id: 'my-first-gate',
  name: 'my-first-gate',
  description: '',
  idType: 'userID',
  lastModifierID: '..',
  ...
}
```

## Update rules

Update rules by passing a rule object to the `update` command. The update replaces the existing rules entirely.

```bash
$ siggy gates update my-first-gate '{
    "rules": [
      {
        "name": "all employees",
        "passPercentage": 100,
        "conditions": [
          {
            "type": "email",
            "operator": "str_contains_any",
            "targetValue": [
              "@statsig.com"
            ]
          }
        ]
      }
    ]
  }'

# Response
{
  id: 'my-first-gate',
  name: 'my-first-gate',
  ...
  rules: [
    {
      id: '729Qb4MVDs0YrIjNR5aOSm',
      name: 'all employees',
      passPercentage: 100,
      conditions: [
        {
          type: 'email',
          targetValue: [ '@statsig.com' ],
          operator: 'str_contains_any'
        }
      ],
    }
  ],
  ...
}
```

## Check if the gate works

When you have configured the Client API key correctly, you can invoke the gate for different users to validate that it works.

If you pass no user object, the CLI creates an empty user object and evaluates the gate against it.

```bash
$ siggy gates check my-first-gate

# Response
{
  name: 'my-first-gate',
  value: false,
  rule_id: 'default',
  group_name: null
}
```

You can also pass a user object crafted as JSON using the `--user` option.

```bash
$ siggy gates check my-first-gate --user '{ "email": "siggy@statsig.com" }'

# Response
{
  name: 'my-first-gate',
  value: true,
  rule_id: '729Qb4MVDs0YrIjNR5aOSm',
  group_name: null
}
```

## List all gates

```bash
$  siggy gates list

# Response
[
  {
    id: 'my-first-gate',
    name: 'my-first-gate',
    lastModifiedTime: 1718222637700,
    lastModifierName: 'CONSOLE API'
  },
  {
    id: 'from_siggy',
    name: 'from_siggy',
    lastModifiedTime: 1717807438090,
    lastModifierName: 'CONSOLE API'
  }
  ...
]
```

## Delete gate

Delete a gate using the CLI. By default, a confirmation prompt requires your input.

```bash
$ siggy gates delete my-first-gate

# Response
Are you sure you want to delete gate (id: my-first-gate)? (y/n): 
```

Use the `--force` option to skip the confirmation prompt.

```bash
$ siggy gates delete my-first-gate --force

# Response
Gate deleted successfully.
```
