Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement detail command #53

Merged
merged 3 commits into from
Mar 13, 2024
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ The `cloudsite` tool will now use your the above configured access key by defaul
- [`configuration`](#cloudsite-configuration): Command group for managing the Cloudsite CLI configuration.
- [`create`](#cloudsite-create): Creates a new website, setting up infrastructure and copying content.
- [`destroy`](#cloudsite-destroy): Destroys the named site. I.e., deletes all cloud resources associated with the site.
- [`detail`](#cloudsite-detail): Prints details for the indicated site.
- [`list`](#cloudsite-list): Lists the sites registered in the local database.
- [`plugin-settings`](#cloudsite-plugin-settings): Sets (or deletes) a site option.
- [`update`](#cloudsite-update): Updates a website content and/or infrastructure.
Expand Down Expand Up @@ -253,6 +254,18 @@ Destroys the named site. I.e., deletes all cloud resources associated with the s
|`[apex-domain]`|(_main argument_,_required_) The domain of the site to delete.|
|`--confirmed`|Skips the interactive confirmation and destroys the resources without further confirmation.|

<span id="cloudsite-detail"></span>
#### `cloudsite detail <options> [apex-domain]`

Prints details for the indicated site.

##### `detail` options

|Option|Description|
|------|------|
|`[apex-domain]`|(_main argument_,_required_) The domain of the site to detail.|
|`--format`|Sets the format for the output. May be 'terminal' (default), 'text', 'json', or 'yaml'.|

<span id="cloudsite-list"></span>
#### `cloudsite list <options>`

Expand Down
3 changes: 3 additions & 0 deletions src/cli/cloudsite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { cliSpec, GLOBAL_OPTIONS_PATH, SITES_INFO_PATH } from './constants'
import { handleConfiguration } from './lib/handle-configuration'
import { handleCreate } from './lib/handle-create'
import { handleDestroy } from './lib/handle-destroy'
import { handleDetail } from './lib/handle-detail'
import { handleList } from './lib/handle-list'
import { handlePluginSettings } from './lib/handle-plugin-settings'
import { handleUpdate } from './lib/handle-update'
Expand Down Expand Up @@ -53,6 +54,8 @@ const cloudsite = async () => {
await handleCreate({ argv, globalOptions, sitesInfo }); break
case 'destroy':
await handleDestroy({ argv, globalOptions, sitesInfo }); break
case 'detail':
await handleDetail({ argv, globalOptions, sitesInfo }); break
case 'document':
console.log(commandLineDocumentation(cliSpec, { sectionDepth : 2, title : 'Command reference' }))
break
Expand Down
16 changes: 16 additions & 0 deletions src/cli/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ const cliSpec = {
}
]
},
{
name : 'detail',
description : 'Prints details for the indicated site.',
arguments : [
{
name : 'apex-domain',
description : 'The domain of the site to detail.',
defaultOption : true,
required : true
},
{
name : 'format',
description : "Sets the format for the output. May be 'terminal' (default), 'text', 'json', or 'yaml'."
}
]
},
{
name : 'list',
description : 'Lists the sites registered in the local database.',
Expand Down
17 changes: 17 additions & 0 deletions src/cli/lib/format-output.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import yaml from 'js-yaml'
import { jsonToPlainText } from 'json-to-plain-text'

const formatOutput = ({ output, format }) => {
if (format === 'json') {
process.stdout.write(JSON.stringify(output, null, ' ') + '\n')
} else if (format === 'yaml') {
process.stdout.write(yaml.dump(output))
} else {
const options = { color : format !== 'text' }
const text = jsonToPlainText(output, options)

process.stdout.write(text + '\n')
}
}

export { formatOutput }
26 changes: 26 additions & 0 deletions src/cli/lib/handle-detail.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import commandLineArgs from 'command-line-args'

import { cliSpec } from '../constants'
import { errorOut } from './error-out'
import { formatOutput } from './format-output'

const handleDetail = ({ argv, sitesInfo }) => {
const detailOptionsSpec = cliSpec.commands.find(({ name }) => name === 'detail').arguments
const detailOptions = commandLineArgs(detailOptionsSpec, { argv })
const apexDomain = detailOptions['apex-domain']
const { format } = detailOptions

if (apexDomain === undefined) {
errorOut('Apex domain must be specified.')
}

const output = sitesInfo[apexDomain]

if (output === undefined) {
errorOut(`No such site '${apexDomain}' found.`)
}

formatOutput({ output, format })
}

export { handleDetail }
14 changes: 2 additions & 12 deletions src/cli/lib/handle-list.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import commandLineArgs from 'command-line-args'
import yaml from 'js-yaml'
import { jsonToPlainText } from 'json-to-plain-text'
import pick from 'lodash/pick'

import { cliSpec } from '../constants'
import { formatOutput } from './format-output'

const handleList = ({ argv, sitesInfo }) => {
const listOptionsSpec = cliSpec.commands.find(({ name }) => name === 'list').arguments
Expand All @@ -20,16 +19,7 @@ const handleList = ({ argv, sitesInfo }) => {
return trimmed
})

if (format === 'json') {
process.stdout.write(JSON.stringify(output, null, ' ') + '\n')
} else if (format === 'yaml') {
process.stdout.write(yaml.dump(output))
} else {
const options = { color : format !== 'text' }
const text = jsonToPlainText(output, options)

process.stdout.write(text + '\n')
}
formatOutput({ output, format })
}

export { handleList }