Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/azdo_help_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,22 @@ Aliases
ls, l
```

#### `azdo pipelines queue show [ORGANIZATION/]PROJECT/QUEUE [flags]`

Show details of an agent queue

```
-q, --jq expression Filter JSON output using a jq expression
--json fields[=*] Output JSON with the specified fields. Prefix a field with '-' to exclude it.
-t, --template string Format JSON output using a Go template; see "azdo help formatting"
```

Aliases

```
view, status
```

### `azdo pipelines run [ORGANIZATION/]PROJECT/PIPELINE [flags]`

Queue a pipeline run
Expand Down
1 change: 1 addition & 0 deletions docs/azdo_pipelines_queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and connect a project to an agent pool.
### Available commands

* [azdo pipelines queue list](./azdo_pipelines_queue_list.md)
* [azdo pipelines queue show](./azdo_pipelines_queue_show.md)

### Examples

Expand Down
52 changes: 52 additions & 0 deletions docs/azdo_pipelines_queue_show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## Command `azdo pipelines queue show`

```
azdo pipelines queue show [ORGANIZATION/]PROJECT/QUEUE [flags]
```

Display the details of a single Azure DevOps agent queue.
The queue is identified by integer ID or name, with an
optional organization prefix.


### Options


* `-q`, `--jq` `expression`

Filter JSON output using a jq expression

* `--json` `fields`

Output JSON with the specified fields. Prefix a field with '-' to exclude it.

* `-t`, `--template` `string`

Format JSON output using a Go template; see "azdo help formatting"


### ALIASES

- `view`
- `status`

### JSON Fields

`id`, `name`, `pool`, `projectId`

### Examples

```bash
# Show a queue by ID
azdo pipelines queue show Fabrikam/7

# Show a queue by name
azdo pipelines queue show 'Fabrikam/Default'

# Show a queue in a specific organization
azdo pipelines queue show 'myorg/Fabrikam/Default'
```

### See also

* [azdo pipelines queue](./azdo_pipelines_queue.md)
2 changes: 2 additions & 0 deletions internal/cmd/pipelines/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/spf13/cobra"

"github.com/tmeckel/azdo-cli/internal/cmd/pipelines/queue/list"
"github.com/tmeckel/azdo-cli/internal/cmd/pipelines/queue/show"
"github.com/tmeckel/azdo-cli/internal/cmd/util"
)

Expand All @@ -23,5 +24,6 @@ func NewCmd(ctx util.CmdContext) *cobra.Command {
}

cmd.AddCommand(list.NewCmd(ctx))
cmd.AddCommand(show.NewCmd(ctx))
return cmd
}
161 changes: 161 additions & 0 deletions internal/cmd/pipelines/queue/show/show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package show

import (
_ "embed"
"fmt"
"strconv"
"strings"

"github.com/MakeNowJust/heredoc/v2"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/taskagent"
"github.com/spf13/cobra"
"go.uber.org/zap"

"github.com/tmeckel/azdo-cli/internal/cmd/util"
"github.com/tmeckel/azdo-cli/internal/template"
"github.com/tmeckel/azdo-cli/internal/types"
)

type showOptions struct {
targetArg string
exporter util.Exporter
}

//go:embed show.tpl
var showTempl string

func NewCmd(ctx util.CmdContext) *cobra.Command {
opts := &showOptions{}

cmd := &cobra.Command{
Use: "show [ORGANIZATION/]PROJECT/QUEUE",
Short: "Show details of an agent queue",
Long: heredoc.Doc(`
Display the details of a single Azure DevOps agent queue.
The queue is identified by integer ID or name, with an
optional organization prefix.
`),
Example: heredoc.Doc(`
# Show a queue by ID
azdo pipelines queue show Fabrikam/7

# Show a queue by name
azdo pipelines queue show 'Fabrikam/Default'

# Show a queue in a specific organization
azdo pipelines queue show 'myorg/Fabrikam/Default'
`),
Aliases: []string{"view", "status"},
Args: util.ExactArgs(1, "queue target is required"),
RunE: func(cmd *cobra.Command, args []string) error {
opts.targetArg = args[0]
return runShow(ctx, opts)
},
}

util.AddJSONFlags(cmd, &opts.exporter, []string{
"id", "name", "pool", "projectId",
})

return cmd
}

func runShow(cmdCtx util.CmdContext, opts *showOptions) error {
ios, err := cmdCtx.IOStreams()
if err != nil {
return err
}
ios.StartProgressIndicator()
defer ios.StopProgressIndicator()

scope, err := util.ParseProjectTargetWithDefaultOrganization(cmdCtx, opts.targetArg)
if err != nil {
return util.FlagErrorWrap(err)
}

if len(scope.Targets) == 0 {
return util.FlagErrorf("queue target is required")
}
taskClient, err := cmdCtx.ClientFactory().TaskAgent(cmdCtx.Context(), scope.Organization)
if err != nil {
return fmt.Errorf("failed to create task agent client: %w", err)
}

queueID, err := strconv.Atoi(scope.Targets[0])
if err == nil {
if queueID <= 0 {
return util.FlagErrorf("invalid queue id %d", queueID)
}
} else {
queues, listErr := taskClient.GetAgentQueues(cmdCtx.Context(), taskagent.GetAgentQueuesArgs{
Project: types.ToPtr(scope.Project),
QueueName: types.ToPtr(scope.Targets[0]),
})
if listErr != nil {
return fmt.Errorf("failed to list queues: %w", listErr)
}

matchCount := 0
for _, q := range types.GetValue(queues, []taskagent.TaskAgentQueue{}) {
if q.Name == nil || !strings.EqualFold(*q.Name, scope.Targets[0]) {
continue
}
if q.Id == nil {
return fmt.Errorf("queue %q returned without an ID", scope.Targets[0])
}
queueID = *q.Id
matchCount++
}

switch {
case matchCount == 0:
return fmt.Errorf("queue %q not found", scope.Targets[0])
case matchCount > 1:
return fmt.Errorf("multiple queues named %q found; specify the numeric ID", scope.Targets[0])
}
}

zap.L().Debug(
"fetching queue",
zap.String("organization", scope.Organization),
zap.String("project", scope.Project),
zap.Int("queueId", queueID),
)

queue, err := taskClient.GetAgentQueue(cmdCtx.Context(), taskagent.GetAgentQueueArgs{
QueueId: types.ToPtr(queueID),
Project: types.ToPtr(scope.Project),
})
if err != nil {
return fmt.Errorf("failed to get queue: %w", err)
}
if queue == nil {
return fmt.Errorf("queue %q not found", scope.Targets[0])
}

if opts.exporter != nil {
ios.StopProgressIndicator()
return opts.exporter.Write(ios, queue)
}

ios.StopProgressIndicator()

t := template.New(
ios.Out,
ios.TerminalWidth(),
ios.ColorEnabled(),
).
WithTheme(ios.TerminalTheme()).
WithFuncs(map[string]any{
"hasText": template.HasText,
"s": template.StringOrEmpty,
"u": template.UUIDString,
})

err = t.Parse(showTempl)
if err != nil {
return err
}

return t.ExecuteData(queue)
}
4 changes: 4 additions & 0 deletions internal/cmd/pipelines/queue/show/show.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{bold "id:"}} {{.Id}}
{{bold "name:"}} {{s .Name}}
{{if .ProjectId}}{{bold "project id:"}} {{u .ProjectId}}{{end}}
{{if .Pool}}{{bold "pool:"}} {{if .Pool.Id}}{{.Pool.Id}}{{end}}{{if hasText (s .Pool.Name)}} ({{s .Pool.Name}}){{end}}{{end}}
Loading
Loading