Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit a81b1b3

Browse files
authored
made default to non-suspended; cleaned up columns (#38)
1 parent df906b5 commit a81b1b3

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

commands/services/list.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { apiGetAction, Subcommand } from "../_helpers.ts";
22
import { getConfig } from "../../config/index.ts";
33
import { getRequestJSONList } from "../../api/index.ts";
44
import { getLogger } from "../../util/logging.ts";
5+
import { funcError } from "../../util/errors.ts";
6+
import { RenderCLIError } from "../../errors.ts";
57

68
const desc =
79
`Lists the services this user can see.`;
@@ -15,7 +17,7 @@ export const servicesListCommand =
1517
default: 'table',
1618
})
1719
.option("--columns <cols:string[]>", "if --format table, the columns to show.", {
18-
default: ['id', 'name', 'type', 'slug', 'suspended'],
20+
default: ['id', 'name', 'type', 'serviceDetails.env', 'slug', 'serviceDetails.numInstances'],
1921
})
2022
.group("API parameters")
2123
.option("--name <name:string[]>", "the name of a service to filter by", { collect: true })
@@ -27,6 +29,10 @@ export const servicesListCommand =
2729
.option("--created-after <datetime>", "services created after (ISO8601)")
2830
.option("--updated-before <datetime>", "services updated before (ISO8601)")
2931
.option("--updated-after <datetime>", "services updated after (ISO8601)")
32+
.group("API-nonstandard parameters")
33+
.option("--suspended <susp:string>", "'true'/'yes', 'false'/'no', or 'all'", {
34+
default: 'false',
35+
})
3036
.action((opts) => apiGetAction({
3137
format: opts.format,
3238
tableColumns: opts.columns,
@@ -44,6 +50,14 @@ export const servicesListCommand =
4450
type: opts.type?.flat(Infinity),
4551
env: opts.env?.flat(Infinity),
4652
region: opts.serviceRegion?.flat(Infinity),
53+
suspended:
54+
opts.suspended === 'all'
55+
? ['suspended', 'not_suspended' ]
56+
: ['true', 'yes'].includes(opts.suspended.toLowerCase())
57+
? ['suspended']
58+
: ['false', 'no'].includes(opts.suspended.toLowerCase())
59+
? ['not_suspended']
60+
: funcError(new RenderCLIError(`invalid --suspended: ${opts.suspended}`)),
4761
createdBefore: opts.createdBefore,
4862
createdAfter: opts.createdAfter,
4963
updatedBefore: opts.updatedBefore,

util/errors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// any here lets us use `funcError` in a ternary tree
2+
// deno-lint-ignore no-explicit-any
3+
export function funcError<T = any>(err: Error): T {
4+
throw err;
5+
}

0 commit comments

Comments
 (0)