@switchbot/openapi-cli 1.0.0 → 1.1.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.
@@ -1,240 +1,240 @@
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
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
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
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
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'
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
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
- }
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
218
  `;
219
219
  export function registerCompletionCommand(program) {
220
220
  const completion = program
221
221
  .command('completion')
222
222
  .description('Print a shell completion script for bash, zsh, fish, or powershell')
223
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
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
238
  `)
239
239
  .action((shell) => {
240
240
  switch (shell.toLowerCase()) {