@switchbot/openapi-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,259 @@
1
+ const BASH_SCRIPT = `# switchbot bash completion
2
+ # Install: source <(switchbot completion bash)
3
+ # Or add to ~/.bashrc:
4
+ # source <(switchbot completion bash)
5
+
6
+ _switchbot_completion() {
7
+ local cur prev words cword
8
+ _get_comp_words_by_ref -n : cur prev words cword 2>/dev/null || {
9
+ cur="\${COMP_WORDS[COMP_CWORD]}"
10
+ prev="\${COMP_WORDS[COMP_CWORD-1]}"
11
+ words=("\${COMP_WORDS[@]}")
12
+ cword="\${COMP_CWORD}"
13
+ }
14
+
15
+ local top_cmds="config devices scenes webhook completion help"
16
+ local config_sub="set-token show"
17
+ local devices_sub="list status command types commands"
18
+ local scenes_sub="list execute"
19
+ local webhook_sub="setup query update delete"
20
+ local completion_shells="bash zsh fish powershell"
21
+ local global_opts="--json --verbose -v --dry-run --timeout --config --help -h --version -V"
22
+
23
+ if [[ \${cword} -eq 1 ]]; then
24
+ COMPREPLY=( $(compgen -W "\${top_cmds} \${global_opts}" -- "\${cur}") )
25
+ return
26
+ fi
27
+
28
+ case "\${words[1]}" in
29
+ config)
30
+ if [[ \${cword} -eq 2 ]]; then
31
+ COMPREPLY=( $(compgen -W "\${config_sub}" -- "\${cur}") )
32
+ fi
33
+ ;;
34
+ devices)
35
+ if [[ \${cword} -eq 2 ]]; then
36
+ COMPREPLY=( $(compgen -W "\${devices_sub}" -- "\${cur}") )
37
+ elif [[ "\${words[2]}" == "command" && "\${prev}" == "--type" ]]; then
38
+ COMPREPLY=( $(compgen -W "command customize" -- "\${cur}") )
39
+ fi
40
+ ;;
41
+ scenes)
42
+ if [[ \${cword} -eq 2 ]]; then
43
+ COMPREPLY=( $(compgen -W "\${scenes_sub}" -- "\${cur}") )
44
+ fi
45
+ ;;
46
+ webhook)
47
+ if [[ \${cword} -eq 2 ]]; then
48
+ COMPREPLY=( $(compgen -W "\${webhook_sub}" -- "\${cur}") )
49
+ elif [[ "\${words[2]}" == "update" ]]; then
50
+ COMPREPLY=( $(compgen -W "--enable --disable \${global_opts}" -- "\${cur}") )
51
+ fi
52
+ ;;
53
+ completion)
54
+ if [[ \${cword} -eq 2 ]]; then
55
+ COMPREPLY=( $(compgen -W "\${completion_shells}" -- "\${cur}") )
56
+ fi
57
+ ;;
58
+ *)
59
+ COMPREPLY=( $(compgen -W "\${global_opts}" -- "\${cur}") )
60
+ ;;
61
+ esac
62
+ }
63
+
64
+ complete -F _switchbot_completion switchbot
65
+ `;
66
+ const ZSH_SCRIPT = `# switchbot zsh completion
67
+ # Install: source <(switchbot completion zsh)
68
+ # Or add to ~/.zshrc:
69
+ # source <(switchbot completion zsh)
70
+
71
+ _switchbot() {
72
+ local -a top_cmds config_sub devices_sub scenes_sub webhook_sub completion_shells
73
+ top_cmds=(
74
+ 'config:Manage API credentials'
75
+ 'devices:List and control devices'
76
+ 'scenes:List and execute scenes'
77
+ 'webhook:Manage webhook configuration'
78
+ 'completion:Print a shell completion script'
79
+ 'help:Show help for a command'
80
+ )
81
+ config_sub=('set-token:Save token + secret' 'show:Show current credential source')
82
+ devices_sub=(
83
+ 'list:List all devices'
84
+ 'status:Query device status'
85
+ 'command:Send a control command'
86
+ 'types:List known device types (offline)'
87
+ 'commands:Show commands for a device type (offline)'
88
+ )
89
+ scenes_sub=('list:List manual scenes' 'execute:Run a scene')
90
+ webhook_sub=(
91
+ 'setup:Register a webhook URL'
92
+ 'query:Query configured webhooks'
93
+ 'update:Enable/disable a webhook'
94
+ 'delete:Delete a webhook'
95
+ )
96
+ completion_shells=('bash' 'zsh' 'fish' 'powershell')
97
+
98
+ local global_opts
99
+ global_opts=(
100
+ '--json[Raw JSON output]'
101
+ '(-v --verbose)'{-v,--verbose}'[Log HTTP details to stderr]'
102
+ '--dry-run[Print mutating requests without sending]'
103
+ '--timeout[HTTP timeout in ms]:ms:'
104
+ '--config[Override credential file path]:path:_files'
105
+ '(-h --help)'{-h,--help}'[Show help]'
106
+ '(-V --version)'{-V,--version}'[Show version]'
107
+ )
108
+
109
+ _arguments -C \\
110
+ "1:command:->top" \\
111
+ "2:subcommand:->sub" \\
112
+ "*::arg:->rest" \\
113
+ $global_opts
114
+
115
+ case "$state" in
116
+ top)
117
+ _describe 'command' top_cmds
118
+ ;;
119
+ sub)
120
+ case "$words[2]" in
121
+ config) _describe 'config' config_sub ;;
122
+ devices) _describe 'devices' devices_sub ;;
123
+ scenes) _describe 'scenes' scenes_sub ;;
124
+ webhook) _describe 'webhook' webhook_sub ;;
125
+ completion) _values 'shell' $completion_shells ;;
126
+ esac
127
+ ;;
128
+ rest)
129
+ if [[ "$words[2]" == "webhook" && "$words[3]" == "update" ]]; then
130
+ _values 'flag' '--enable' '--disable'
131
+ fi
132
+ ;;
133
+ esac
134
+ }
135
+
136
+ compdef _switchbot switchbot
137
+ `;
138
+ const FISH_SCRIPT = `# switchbot fish completion
139
+ # Install:
140
+ # switchbot completion fish > ~/.config/fish/completions/switchbot.fish
141
+
142
+ complete -c switchbot -f
143
+
144
+ # Global options
145
+ complete -c switchbot -l json -d 'Raw JSON output'
146
+ complete -c switchbot -s v -l verbose -d 'Log HTTP details to stderr'
147
+ complete -c switchbot -l dry-run -d 'Print mutating requests without sending'
148
+ complete -c switchbot -l timeout -r -d 'HTTP timeout in ms'
149
+ complete -c switchbot -l config -r -d 'Credential file path'
150
+ complete -c switchbot -s h -l help -d 'Show help'
151
+ complete -c switchbot -s V -l version -d 'Show version'
152
+
153
+ # Top-level commands
154
+ complete -c switchbot -n '__fish_use_subcommand' -a 'config' -d 'Manage API credentials'
155
+ complete -c switchbot -n '__fish_use_subcommand' -a 'devices' -d 'List and control devices'
156
+ complete -c switchbot -n '__fish_use_subcommand' -a 'scenes' -d 'List and execute scenes'
157
+ complete -c switchbot -n '__fish_use_subcommand' -a 'webhook' -d 'Manage webhook configuration'
158
+ complete -c switchbot -n '__fish_use_subcommand' -a 'completion' -d 'Print a shell completion script'
159
+ complete -c switchbot -n '__fish_use_subcommand' -a 'help' -d 'Show help'
160
+
161
+ # config
162
+ complete -c switchbot -n '__fish_seen_subcommand_from config' -a 'set-token show'
163
+
164
+ # devices
165
+ complete -c switchbot -n '__fish_seen_subcommand_from devices' -a 'list status command types commands'
166
+
167
+ # scenes
168
+ complete -c switchbot -n '__fish_seen_subcommand_from scenes' -a 'list execute'
169
+
170
+ # webhook
171
+ complete -c switchbot -n '__fish_seen_subcommand_from webhook' -a 'setup query update delete'
172
+ complete -c switchbot -n '__fish_seen_subcommand_from webhook; and __fish_seen_subcommand_from update' -l enable -d 'Enable the webhook'
173
+ complete -c switchbot -n '__fish_seen_subcommand_from webhook; and __fish_seen_subcommand_from update' -l disable -d 'Disable the webhook'
174
+
175
+ # completion
176
+ complete -c switchbot -n '__fish_seen_subcommand_from completion' -a 'bash zsh fish powershell'
177
+ `;
178
+ const POWERSHELL_SCRIPT = `# switchbot PowerShell completion
179
+ # Install: switchbot completion powershell | Out-String | Invoke-Expression
180
+ # Or add to your profile:
181
+ # switchbot completion powershell >> $PROFILE
182
+
183
+ Register-ArgumentCompleter -Native -CommandName switchbot -ScriptBlock {
184
+ param($wordToComplete, $commandAst, $cursorPosition)
185
+
186
+ $tokens = $commandAst.CommandElements | ForEach-Object { $_.ToString() }
187
+ $count = $tokens.Count
188
+
189
+ $top = 'config','devices','scenes','webhook','completion','help'
190
+ $configSub = 'set-token','show'
191
+ $devicesSub = 'list','status','command','types','commands'
192
+ $scenesSub = 'list','execute'
193
+ $webhookSub = 'setup','query','update','delete'
194
+ $shells = 'bash','zsh','fish','powershell'
195
+ $globalOpts = '--json','--verbose','-v','--dry-run','--timeout','--config','--help','-h','--version','-V'
196
+
197
+ function _emit($values) {
198
+ $values |
199
+ Where-Object { $_ -like "$wordToComplete*" } |
200
+ ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }
201
+ }
202
+
203
+ if ($count -le 2) { return _emit ($top + $globalOpts) }
204
+
205
+ switch ($tokens[1]) {
206
+ 'config' { if ($count -eq 3) { return _emit $configSub } }
207
+ 'devices' { if ($count -eq 3) { return _emit $devicesSub } }
208
+ 'scenes' { if ($count -eq 3) { return _emit $scenesSub } }
209
+ 'webhook' {
210
+ if ($count -eq 3) { return _emit $webhookSub }
211
+ if ($tokens[2] -eq 'update') { return _emit ('--enable','--disable' + $globalOpts) }
212
+ }
213
+ 'completion' { if ($count -eq 3) { return _emit $shells } }
214
+ }
215
+
216
+ return _emit $globalOpts
217
+ }
218
+ `;
219
+ export function registerCompletionCommand(program) {
220
+ const completion = program
221
+ .command('completion')
222
+ .description('Print a shell completion script for bash, zsh, fish, or powershell')
223
+ .argument('<shell>', 'Shell to generate completion for: bash | zsh | fish | powershell')
224
+ .addHelpText('after', `
225
+ The command writes the completion script to stdout. Redirect it to a file or
226
+ source it directly:
227
+
228
+ bash source <(switchbot completion bash)
229
+ # persist: echo 'source <(switchbot completion bash)' >> ~/.bashrc
230
+
231
+ zsh source <(switchbot completion zsh)
232
+ # persist: echo 'source <(switchbot completion zsh)' >> ~/.zshrc
233
+
234
+ fish switchbot completion fish > ~/.config/fish/completions/switchbot.fish
235
+
236
+ powershell switchbot completion powershell | Out-String | Invoke-Expression
237
+ # persist: switchbot completion powershell >> $PROFILE
238
+ `)
239
+ .action((shell) => {
240
+ switch (shell.toLowerCase()) {
241
+ case 'bash':
242
+ process.stdout.write(BASH_SCRIPT);
243
+ return;
244
+ case 'zsh':
245
+ process.stdout.write(ZSH_SCRIPT);
246
+ return;
247
+ case 'fish':
248
+ process.stdout.write(FISH_SCRIPT);
249
+ return;
250
+ case 'powershell':
251
+ case 'pwsh':
252
+ process.stdout.write(POWERSHELL_SCRIPT);
253
+ return;
254
+ default:
255
+ completion.error(`error: unsupported shell "${shell}" (choose from: bash, zsh, fish, powershell)`, { exitCode: 2, code: 'switchbot.unsupportedShell' });
256
+ }
257
+ });
258
+ }
259
+ //# sourceMappingURL=completion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion.js","sourceRoot":"","sources":["../../src/commands/completion.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgEnB,CAAC;AAEF,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuElB,CAAC;AAEF,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCnB,CAAC;AAEF,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCzB,CAAC;AAEF,MAAM,UAAU,yBAAyB,CAAC,OAAgB;IACxD,MAAM,UAAU,GAAG,OAAO;SACvB,OAAO,CAAC,YAAY,CAAC;SACrB,WAAW,CAAC,oEAAoE,CAAC;SACjF,QAAQ,CAAC,SAAS,EAAE,kEAAkE,CAAC;SACvF,WAAW,CAAC,OAAO,EAAE;;;;;;;;;;;;;;CAczB,CAAC;SACG,MAAM,CAAC,CAAC,KAAa,EAAE,EAAE;QACxB,QAAQ,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YAC5B,KAAK,MAAM;gBACT,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;gBAClC,OAAO;YACT,KAAK,KAAK;gBACR,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBACjC,OAAO;YACT,KAAK,MAAM;gBACT,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;gBAClC,OAAO;YACT,KAAK,YAAY,CAAC;YAClB,KAAK,MAAM;gBACT,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;gBACxC,OAAO;YACT;gBACE,UAAU,CAAC,KAAK,CACd,6BAA6B,KAAK,8CAA8C,EAChF,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,4BAA4B,EAAE,CACpD,CAAC;QACN,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function registerConfigCommand(program: Command): void;
@@ -0,0 +1,37 @@
1
+ import { saveConfig, showConfig } from '../config.js';
2
+ import chalk from 'chalk';
3
+ export function registerConfigCommand(program) {
4
+ const config = program
5
+ .command('config')
6
+ .description('Manage SwitchBot API credentials')
7
+ .addHelpText('after', `
8
+ Credential priority:
9
+ 1. Environment variables: SWITCHBOT_TOKEN and SWITCHBOT_SECRET
10
+ 2. File: ~/.switchbot/config.json (created by 'config set-token')
11
+
12
+ Obtain your token/secret from the SwitchBot mobile app:
13
+ Profile → Preferences → Developer Options → Get Token
14
+ `);
15
+ config
16
+ .command('set-token')
17
+ .description('Save token and secret to ~/.switchbot/config.json (mode 0600)')
18
+ .argument('<token>', 'API token (long hex string from the SwitchBot app)')
19
+ .argument('<secret>', 'API client secret (hex string from the SwitchBot app)')
20
+ .addHelpText('after', `
21
+ Example:
22
+ $ switchbot config set-token 0123abcd... 9876ffff...
23
+
24
+ Note: the file is written with mode 0600 so only your user can read it.
25
+ `)
26
+ .action((token, secret) => {
27
+ saveConfig(token, secret);
28
+ console.log(chalk.green('✓ Credentials saved to ~/.switchbot/config.json'));
29
+ });
30
+ config
31
+ .command('show')
32
+ .description('Show the current credential source and a masked secret')
33
+ .action(() => {
34
+ showConfig();
35
+ });
36
+ }
37
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,MAAM,MAAM,GAAG,OAAO;SACnB,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,kCAAkC,CAAC;SAC/C,WAAW,CAAC,OAAO,EAAE;;;;;;;CAOzB,CAAC,CAAC;IAED,MAAM;SACH,OAAO,CAAC,WAAW,CAAC;SACpB,WAAW,CAAC,+DAA+D,CAAC;SAC5E,QAAQ,CAAC,SAAS,EAAE,oDAAoD,CAAC;SACzE,QAAQ,CAAC,UAAU,EAAE,uDAAuD,CAAC;SAC7E,WAAW,CAAC,OAAO,EAAE;;;;;CAKzB,CAAC;SACG,MAAM,CAAC,CAAC,KAAa,EAAE,MAAc,EAAE,EAAE;QACxC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;IAEL,MAAM;SACH,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,wDAAwD,CAAC;SACrE,MAAM,CAAC,GAAG,EAAE;QACX,UAAU,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function registerDevicesCommand(program: Command): void;