Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,35 +284,37 @@ cloudcannon orgs list

---

### `orgs get --org <name|id|uuid>`
### `orgs get [org]`

Get an organisation by name, ID, or UUID.
Get an organization by name, ID, or UUID. If you belong to only one organization, it is selected automatically.

```sh
cloudcannon orgs get --org my-org
cloudcannon orgs get
```

**Flags**

| Flag | Description |
|---|---|
| `--org <name\|id\|uuid>` | The organisation name, ID, or UUID (required) |
| `--org <name\|id\|uuid>` | The organization name, ID, or UUID |

---

### `orgs sites list --org <name|id|uuid>`
### `orgs sites list [org]`

List all sites for an organisation.
List all sites for an organization. If you belong to only one organization, it is selected automatically.

```sh
cloudcannon orgs sites list --org my-org
cloudcannon orgs sites list
```

**Flags**

| Flag | Description |
|---|---|
| `--org <name\|id\|uuid>` | The organisation name, ID, or UUID (required) |
| `--org <name\|id\|uuid>` | The organization name, ID, or UUID |
| `--page <n>` | Page number to fetch |
| `--items <n>` | Number of items per page |
| `--sort-by <field>` | Field name to sort by |
Expand All @@ -321,19 +323,20 @@ cloudcannon orgs sites list --org my-org

---

### `orgs inboxes list --org <name|id|uuid>`
### `orgs inboxes list [org]`

List all inboxes for an organisation.
List all inboxes for an organization. If you belong to only one organization, it is selected automatically.

```sh
cloudcannon orgs inboxes list --org my-org
cloudcannon orgs inboxes list
```

**Flags**

| Flag | Description |
|---|---|
| `--org <name\|id\|uuid>` | The organisation name, ID, or UUID (required) |
| `--org <name\|id\|uuid>` | The organization name, ID, or UUID |
| `--page <n>` | Page number to fetch |
| `--items <n>` | Number of items per page |
| `--sort-by <field>` | Field name to sort by |
Expand All @@ -352,6 +355,31 @@ cloudcannon sites list

---

### `sites create [source]`

Create a new site connected to a git repository. The `source` positional is a git remote URL with an optional `#branch` suffix.

```sh
# Interactive — prompts for org, name, and source
cloudcannon sites create

# Non-interactive — all fields provided
cloudcannon sites create --org my-org --name my-site https://github.com/owner/repo.git#main
```

Run without all required fields to get interactive prompts for the missing pieces. If you belong to only one organization, it is selected automatically — use `--org` to override. The source URL defaults to your local `git remote get-url origin` if available. After creating the site, a link to open it in CloudCannon is printed.

**Flags**

| Flag | Description |
|---|---|
| `--org <name\|id\|uuid>` | The organization name, ID, or UUID |
| `--name <string>` | The site name |

Supported git hosts: `github.com`, `gitlab.com`, `bitbucket.org`.

---

### `sites get --site <name|id|uuid|domain>`

Get a site by name, ID, UUID, or domain.
Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"!package.json",
"!package-lock.json",
"!.github",
"!toolproof-tests/test-sites"
"!toolproof-tests/test-sites",
"!src/templates"
]
},
"formatter": {
Expand Down
15 changes: 4 additions & 11 deletions src/orgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineCommand } from 'citty';
import { printJson } from './configure/utility.ts';
import { buildListOptions, listFlagDefs } from './list-options.ts';
import { orgsInboxesCommand } from './orgs/inboxes.ts';
import { resolveOrgUuid } from './orgs/resolve.ts';
import { resolveOrg } from './orgs/resolve.ts';
import { orgsSitesCommand } from './orgs/sites.ts';
import { getSdkClient, handleAPIError } from './sdk-client.ts';

Expand Down Expand Up @@ -41,23 +41,16 @@ export const orgsGetCommand = defineCommand({
type: 'string',
description: 'The organisation name, ID, or UUID',
valueHint: 'name|id|uuid',
required: true,
},
},
async run(ctx): Promise<void> {
const client = await getSdkClient();
const orgUuid = await resolveOrgUuid(client, ctx.args.org);
if (!orgUuid) {
const org = await resolveOrg(client, ctx.args.org);
if (!org) {
process.exitCode = 1;
return;
}
try {
const org = await client.org(orgUuid).get();
printJson(org);
} catch (err: unknown) {
handleAPIError(err);
process.exitCode = 1;
}
printJson(org);
},
});

Expand Down
11 changes: 5 additions & 6 deletions src/orgs/inboxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineCommand } from 'citty';
import { printJson } from '../configure/utility.ts';
import { buildListOptions, listFlagDefs } from '../list-options.ts';
import { getSdkClient, handleAPIError } from '../sdk-client.ts';
import { resolveOrgUuid } from './resolve.ts';
import { resolveOrg } from './resolve.ts';

export const orgsInboxesListCommand = defineCommand({
meta: {
Expand All @@ -15,21 +15,20 @@ export const orgsInboxesListCommand = defineCommand({
type: 'string',
description: 'The organisation name, ID, or UUID',
valueHint: 'name|id|uuid',
required: true,
},
...listFlagDefs,
},
async run(ctx): Promise<void> {
const client = await getSdkClient();
const orgUuid = await resolveOrgUuid(client, ctx.args.org);
if (!orgUuid) {
const org = await resolveOrg(client, ctx.args.org);
if (!org) {
process.exitCode = 1;
return;
}
const org = client.org(orgUuid);
const orgClient = client.org(org.uuid);
const options = buildListOptions(ctx.args);
try {
const inboxes = await org.getInboxes(options as ListOrgInboxesOptions);
const inboxes = await orgClient.getInboxes(options as ListOrgInboxesOptions);
printJson({
current_page: inboxes.current_page,
total_pages: inboxes.total_pages,
Expand Down
31 changes: 25 additions & 6 deletions src/orgs/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import type CloudCannonClient from '@cloudcannon/sdk';
import type { ListOrgsOptions } from '@cloudcannon/sdk';
import type { ListOrgsOptions, Org } from '@cloudcannon/sdk';
import { printJson } from '../configure/utility.ts';
import { handleAPIError } from '../sdk-client.ts';

const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;

export async function resolveOrgUuid(
export async function resolveOrg(
client: CloudCannonClient,
identifier: string
): Promise<string | undefined> {
identifier?: string
): Promise<Org | undefined> {
if (!identifier) {
try {
const orgs = await client.orgs();
if (orgs.items.length === 1) {
return orgs.items[0];
}
return;
} catch (err: unknown) {
handleAPIError(err);
return;
}
}

if (UUID_REGEX.test(identifier)) {
return identifier;
try {
return await client.org(identifier).get();
} catch (err: unknown) {
handleAPIError(err);
return;
}
}

const filters: ListOrgsOptions['filters'] = {};
Expand All @@ -21,6 +39,7 @@ export async function resolveOrgUuid(
} else {
filters.search = identifier;
}

try {
const orgs = await client.orgs({ filters });

Expand All @@ -35,7 +54,7 @@ export async function resolveOrgUuid(
return;
}

return orgs.items[0].uuid;
return orgs.items[0];
} catch (err: unknown) {
handleAPIError(err);
return;
Expand Down
11 changes: 5 additions & 6 deletions src/orgs/sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineCommand } from 'citty';
import { printJson } from '../configure/utility.ts';
import { buildListOptions, listFlagDefs } from '../list-options.ts';
import { getSdkClient, handleAPIError } from '../sdk-client.ts';
import { resolveOrgUuid } from './resolve.ts';
import { resolveOrg } from './resolve.ts';

export const orgsSitesListCommand = defineCommand({
meta: {
Expand All @@ -15,21 +15,20 @@ export const orgsSitesListCommand = defineCommand({
type: 'string',
description: 'The organisation name, ID, or UUID',
valueHint: 'name|id|uuid',
required: true,
},
...listFlagDefs,
},
async run(ctx): Promise<void> {
const client = await getSdkClient();
const orgUuid = await resolveOrgUuid(client, ctx.args.org);
if (!orgUuid) {
const org = await resolveOrg(client, ctx.args.org as string | undefined);
if (!org) {
process.exitCode = 1;
return;
}
const org = client.org(orgUuid);
const orgClient = client.org(org.uuid);
const options = buildListOptions(ctx.args);
try {
const sites = await org.sites(options as ListOrgSitesOptions);
const sites = await orgClient.sites(options as ListOrgSitesOptions);
printJson({
current_page: sites.current_page,
total_pages: sites.total_pages,
Expand Down
2 changes: 2 additions & 0 deletions src/sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineCommand } from 'citty';
import { printJson } from './configure/utility.ts';
import { getSdkClient, handleAPIError } from './sdk-client.ts';
import { sitesBuildsCommand } from './sites/builds.ts';
import { sitesCreateCommand } from './sites/create.ts';
import { sitesFilesCommand } from './sites/files.ts';
import {
sitesPrintLastBuildCommand,
Expand Down Expand Up @@ -251,6 +252,7 @@ export const sitesCommand = defineCommand({
subCommands: {
list: sitesListCommand,
get: sitesGetCommand,
create: sitesCreateCommand,
rebuild: sitesRebuildCommand,
'update-build-config': sitesUpdateBuildConfigCommand,
files: sitesFilesCommand,
Expand Down
Loading