MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / buildInstance

Function buildInstance

src/index.ts:12–56  ·  view source on GitHub ↗
(commands: CommandModule<object, any>[])

Source from the content-addressed store, hash-verified

10
11// eslint-disable-next-line @typescript-eslint/no-explicit-any
12export const buildInstance = (commands: CommandModule<object, any>[]): Argv => {
13 const instance: Argv = yargs(hideBin(process.argv))
14 instance
15 .scriptName('smartthings')
16 .version(pkg.version)
17 .command(commands)
18 .strict()
19 .demandCommand()
20 .wrap(Math.min(160, instance.terminalWidth()))
21 .recommendCommands()
22 /* eslint-disable @typescript-eslint/naming-convention */
23 .updateStrings({
24 'Positionals:': 'Arguments:',
25 'Options:': 'Flags:',
26 })
27 .parserConfiguration({
28 'greedy-arrays': false,
29 'strip-aliased': true,
30 'strip-dashed': true,
31 })
32 /* eslint-enable @typescript-eslint/naming-convention */
33 .completion('generate-completions-script', 'output completion script setup')
34 .fail((message, error) => {
35 if (message) {
36 console.error(message)
37 console.error('Run with --help for usage details.')
38 } else if (error && 'isAxiosError' in error && error.isAxiosError) {
39 // We don't print axiosError.message here because it just duplicates the things
40 // we're displaying but unformatted.
41 const axiosError = error as AxiosError
42 console.error(`Request to API failed with status ${axiosError.response?.status}`)
43 if (axiosError.response) {
44 console.error('Response: ', JSON.stringify(axiosError.response.data, null, 4))
45 }
46 } else if (error) {
47 console.error(error.message)
48 } else {
49 console.error('An unknown error occurred.')
50 }
51
52 // eslint-disable-next-line no-process-exit
53 process.exit(1)
54 })
55 return instance
56}

Callers 1

run.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected