torc 0.22.2

Workflow management system
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# Shell Completions

Torc provides shell completion scripts to make working with the CLI faster and more convenient.
Completions help you discover commands, avoid typos, and speed up your workflow.

## Overview

Shell completions provide:

- **Command completion** - Tab-complete `torc` subcommands and options
- **Flag completion** - Tab-complete command-line flags and their values
- **Multi-shell support** - Bash, Zsh, Fish, Elvish, and PowerShell
- **Automatic updates** - Completions are generated from the CLI structure

## Generating Completions

Use the `torc completions` command to generate completion scripts for your shell:

```bash
# See available shells
torc completions --help

# Generate for a specific shell
torc completions bash
torc completions zsh
torc completions fish
torc completions elvish
torc completions powershell
```

## Installation

### Bash

**User installation**

```bash
# Create completions directory if it doesn't exist
mkdir -p ~/.local/share/bash-completion/completions

# Generate and install completions
torc completions bash > ~/.local/share/bash-completion/completions/torc

# Source the completion file in your current shell
source ~/.local/share/bash-completion/completions/torc
```

**Verify installation:**

```bash
# Restart your shell or source the completion file
source ~/.local/share/bash-completion/completions/torc

# Test completions
torc wor<TAB>      # Should complete to "workflows"
torc workflows <TAB>  # Should show workflow subcommands
```

### Zsh

**Option 1: User installation (recommended)**

```bash
# Create completions directory in your home directory
mkdir -p ~/.zfunc

# Add to fpath in your ~/.zshrc if not already present
echo 'fpath=(~/.zfunc $fpath)' >> ~/.zshrc
echo 'autoload -Uz compinit && compinit' >> ~/.zshrc

# Generate and install completions
torc completions zsh > ~/.zfunc/_torc

# Restart shell or source ~/.zshrc
source ~/.zshrc
```

**Option 2: Using custom location**

```bash
# Generate to a custom location
mkdir -p ~/my-completions
torc completions zsh > ~/my-completions/_torc

# Add to ~/.zshrc
echo 'fpath=(~/my-completions $fpath)' >> ~/.zshrc
echo 'autoload -Uz compinit && compinit' >> ~/.zshrc

# Restart shell
exec zsh
```

**Troubleshooting Zsh completions:**

If completions aren't working, try rebuilding the completion cache:

```bash
# Remove completion cache
rm -f ~/.zcompdump

# Restart shell
exec zsh
```

### Fish

```bash
# Fish automatically loads completions from ~/.config/fish/completions/
mkdir -p ~/.config/fish/completions

# Generate and install completions
torc completions fish > ~/.config/fish/completions/torc.fish

# Fish will automatically load the completions
# Test immediately (no shell restart needed)
torc wor<TAB>
```

### Elvish

```bash
# Create completions directory
mkdir -p ~/.elvish/lib

# Generate completions
torc completions elvish > ~/.elvish/lib/torc.elv

# Add to your ~/.elvish/rc.elv
echo 'use torc' >> ~/.elvish/rc.elv

# Restart shell
```

### PowerShell

**Windows PowerShell / PowerShell Core:**

```powershell
# Create profile directory if it doesn't exist
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $PROFILE)

# Generate completions to a file
torc completions powershell > $HOME\.config\torc_completions.ps1

# Add to your PowerShell profile
Add-Content -Path $PROFILE -Value '. $HOME\.config\torc_completions.ps1'

# Reload profile
. $PROFILE
```

**Alternative: Source inline**

```powershell
# Generate and add directly to profile
torc completions powershell | Out-File -Append -FilePath $PROFILE

# Reload profile
. $PROFILE
```

## Using Completions

Once installed, use `Tab` to trigger completions:

### Command Completion

```bash
# Complete subcommands
torc <TAB>
# Shows: workflows, jobs, files, events, run, submit, tui, ...

torc work<TAB>
# Completes to: torc workflows

torc workflows <TAB>
# Shows: create, list, get, delete, submit, run, ...
```

### Flag Completion

```bash
# Complete flags
torc --<TAB>
# Shows: --url, --username, --password, --format, --log-level, --help

torc workflows list --<TAB>
# Shows available flags for the list command

# Complete flag values (where applicable)
torc workflows list --format <TAB>
# Shows: table, json
```

### Workflow ID Completion

```bash
# Some shells support dynamic completion
torc workflows get <TAB>
# May show available workflow IDs
```

## Examples

Here are some common completion patterns:

```bash
# Discover available commands
torc <TAB><TAB>

# Complete command names
torc w<TAB>          # workflows
torc wo<TAB>         # workflows
torc j<TAB>          # jobs

# Navigate subcommands
torc workflows <TAB>  # create, list, get, delete, ...
torc jobs <TAB>       # list, get, update, ...

# Complete flags
torc --u<TAB>         # --url, --username
torc --url <type-url>
torc --format <TAB>   # table, json

# Complex commands
torc create --<TAB>
# Shows all available flags for the create command
```

## Updating Completions

When you update Torc to a new version, regenerate the completion scripts to get the latest commands
and flags:

```bash
# Bash
torc completions bash > ~/.local/share/bash-completion/completions/torc
source ~/.local/share/bash-completion/completions/torc

# Zsh
torc completions zsh > ~/.zfunc/_torc
rm -f ~/.zcompdump && exec zsh

# Fish
torc completions fish > ~/.config/fish/completions/torc.fish
# Fish reloads automatically

# PowerShell
torc completions powershell > $HOME\.config\torc_completions.ps1
. $PROFILE
```

## Automation

You can automate completion installation in your dotfiles or setup scripts:

### Bash Setup Script

```bash
#!/bin/bash
# install-torc-completions.sh

COMPLETION_DIR="$HOME/.local/share/bash-completion/completions"
mkdir -p "$COMPLETION_DIR"

if command -v torc &> /dev/null; then
    torc completions bash > "$COMPLETION_DIR/torc"
    echo "Torc completions installed for Bash"
    echo "Run: source $COMPLETION_DIR/torc"
else
    echo "Error: torc command not found"
    exit 1
fi
```

### Zsh Setup Script

```bash
#!/bin/zsh
# install-torc-completions.zsh

COMPLETION_DIR="$HOME/.zfunc"
mkdir -p "$COMPLETION_DIR"

if command -v torc &> /dev/null; then
    torc completions zsh > "$COMPLETION_DIR/_torc"

    # Add fpath to .zshrc if not already present
    if ! grep -q "fpath=(.*\.zfunc" ~/.zshrc; then
        echo 'fpath=(~/.zfunc $fpath)' >> ~/.zshrc
        echo 'autoload -Uz compinit && compinit' >> ~/.zshrc
    fi

    echo "Torc completions installed for Zsh"
    echo "Run: exec zsh"
else
    echo "Error: torc command not found"
    exit 1
fi
```

### Post-Installation Check

```bash
#!/bin/bash
# verify-completions.sh

# Test if completions are working
if complete -p torc &> /dev/null; then
    echo "✓ Torc completions are installed"
else
    echo "✗ Torc completions are not installed"
    echo "Run: torc completions bash > ~/.local/share/bash-completion/completions/torc"
fi
```

## Troubleshooting

### Completions Not Working

**Problem:** Tab completion doesn't show torc commands.

**Solutions:**

1. **Verify torc is in your PATH:**
   ```bash
   which torc
   # Should show path to torc binary
   ```

2. **Check if completion file exists:**
   ```bash
   # Bash
   ls -l ~/.local/share/bash-completion/completions/torc

   # Zsh
   ls -l ~/.zfunc/_torc

   # Fish
   ls -l ~/.config/fish/completions/torc.fish
   ```

3. **Verify completion is loaded:**
   ```bash
   # Bash
   complete -p torc

   # Zsh
   which _torc
   ```

4. **Reload shell or source completion file:**
   ```bash
   # Bash
   source ~/.local/share/bash-completion/completions/torc

   # Zsh
   exec zsh

   # Fish (automatic)
   ```

### Outdated Completions

**Problem:** New commands or flags don't show in completions.

**Solution:** Regenerate the completion file after updating Torc:

```bash
# Bash
torc completions bash > ~/.local/share/bash-completion/completions/torc
source ~/.local/share/bash-completion/completions/torc

# Zsh
torc completions zsh > ~/.zfunc/_torc
rm ~/.zcompdump && exec zsh

# Fish
torc completions fish > ~/.config/fish/completions/torc.fish
```

### Permission Denied

**Problem:** Cannot write to system completion directory.

**Solution:** Use user-level completion directory or sudo:

```bash
# Use user directory (recommended)
mkdir -p ~/.local/share/bash-completion/completions
torc completions bash > ~/.local/share/bash-completion/completions/torc

# Or use sudo for system-wide
sudo torc completions bash > /etc/bash_completion.d/torc
```

### Zsh "command not found: compdef"

**Problem:** Zsh completion system not initialized.

**Solution:** Add to your `~/.zshrc`:

```bash
autoload -Uz compinit && compinit
```

### PowerShell Execution Policy

**Problem:** Cannot run completion script due to execution policy.

**Solution:** Adjust execution policy:

```powershell
# Check current policy
Get-ExecutionPolicy

# Set policy to allow local scripts
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```

## Shell-Specific Features

### Bash

- Case-insensitive completion (if configured in `.inputrc`)
- Partial matching support
- Menu completion available

### Zsh

- Advanced completion with descriptions
- Correction suggestions
- Menu selection
- Color support for completions

### Fish

- Rich descriptions for each option
- Real-time syntax highlighting
- Automatic paging for long completion lists
- Fuzzy matching support

### PowerShell

- IntelliSense-style completions
- Parameter descriptions
- Type-aware completions

## Best Practices

1. **Keep completions updated**: Regenerate after each Torc update
2. **Use version control**: Include completion installation in dotfiles
3. **Automate installation**: Add to setup scripts for new machines
4. **Test after updates**: Verify completions work after shell or Torc updates
5. **Document in team wikis**: Help teammates set up completions

## Additional Resources

- [Bash Completion Documentation]https://github.com/scop/bash-completion
- [Zsh Completion System]http://zsh.sourceforge.net/Doc/Release/Completion-System.html
- [Fish Completion Tutorial]https://fishshell.com/docs/current/completions.html
- [PowerShell Tab Completion]https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_tab_expansion