Skip to content

Commit

Permalink
Merge pull request #53 from zanerock/work-liquid-labs/cloudsite/52
Browse files Browse the repository at this point in the history
Implement detail command
  • Loading branch information
zanerock authored Mar 13, 2024
2 parents d74ff89 + 30a791b commit 53fa9ab
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 12 deletions.
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 }

0 comments on commit 53fa9ab

Please sign in to comment.