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 @@ -1341,6 +1341,22 @@ Aliases
ls, l
```

### `azdo team show [ORGANIZATION/]PROJECT/TEAM [flags]`

Show details of a team.

```
-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

```
s
```



### See also
Expand Down
1 change: 1 addition & 0 deletions docs/azdo_team.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Manage Azure DevOps teams.

* [azdo team create](./azdo_team_create.md)
* [azdo team list](./azdo_team_list.md)
* [azdo team show](./azdo_team_show.md)

### ALIASES

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

```
azdo team show [ORGANIZATION/]PROJECT/TEAM [flags]
```

Show details of a single team in a project. The team is identified by its
name or GUID inside the project. The organization falls back to the
configured default when omitted.


### 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

- `s`

### JSON Fields

`description`, `id`, `identity`, `identityUrl`, `name`, `projectId`, `projectName`, `url`

### Examples

```bash
# Show a team by name in the default organization
azdo team show Fabrikam/"Fabrikam Engineering"

# Show a team by ID in a specific organization
azdo team show MyOrg/Fabrikam/00000002-0000-0000-0000-000000000000
```

### See also

* [azdo team](./azdo_team.md)
154 changes: 154 additions & 0 deletions internal/cmd/team/show/show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package show

import (
_ "embed"
"fmt"

"github.com/MakeNowJust/heredoc/v2"
"github.com/google/uuid"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/core"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/identity"
"github.com/spf13/cobra"
"github.com/tmeckel/azdo-cli/internal/cmd/util"
"github.com/tmeckel/azdo-cli/internal/iostreams"
"github.com/tmeckel/azdo-cli/internal/template"
"github.com/tmeckel/azdo-cli/internal/types"
"go.uber.org/zap"
)

type showOptions struct {
targetArg string
exporter util.Exporter
}

//go:embed show.tpl
var showTpl string

type teamTemplateData struct {
Id string
Name string
Description string
ProjectId string
ProjectName string
Url string
Identity string
}

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

cmd := &cobra.Command{
Use: "show [ORGANIZATION/]PROJECT/TEAM",
Short: "Show details of a team.",
Long: heredoc.Doc(`
Show details of a single team in a project. The team is identified by its
name or GUID inside the project. The organization falls back to the
configured default when omitted.
`),
Example: heredoc.Doc(`
# Show a team by name in the default organization
azdo team show Fabrikam/"Fabrikam Engineering"

# Show a team by ID in a specific organization
azdo team show MyOrg/Fabrikam/00000002-0000-0000-0000-000000000000
`),
Aliases: []string{"s"},
Args: util.ExactArgs(1, "team argument 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", "description", "url",
"identity", "identityUrl", "projectId", "projectName",
})

return cmd
}

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

ios.StartProgressIndicator()
defer ios.StopProgressIndicator()

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

zap.L().Debug("show team",
zap.String("organization", scope.Organization),
zap.String("project", scope.Project),
zap.String("teamId", scope.Targets[0]),
)

client, err := ctx.ClientFactory().Core(ctx.Context(), scope.Organization)
if err != nil {
return fmt.Errorf("failed to create Core client: %w", err)
}

team, err := client.GetTeam(ctx.Context(), core.GetTeamArgs{
ProjectId: &scope.Project,
TeamId: &scope.Targets[0],
})
if err != nil {
return fmt.Errorf("failed to get team: %w", err)
}

ios.StopProgressIndicator()

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

return renderTeam(ctx, ios, team)
}

func renderTeam(ctx util.CmdContext, ios *iostreams.IOStreams, team *core.WebApiTeam) error {
data := teamTemplateData{
Id: types.GetValue(team.Id, uuid.UUID{}).String(),
Name: types.GetValue(team.Name, ""),
Description: types.GetValue(team.Description, ""),
ProjectId: types.GetValue(team.ProjectId, uuid.UUID{}).String(),
ProjectName: types.GetValue(team.ProjectName, ""),
Url: types.GetValue(team.Url, ""),
Identity: formatIdentity(team.Identity),
}

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

if err := t.Parse(showTpl); err != nil {
return err
}

return t.ExecuteData(data)
}

func formatIdentity(ident *identity.Identity) string {
if ident == nil {
return ""
}
displayName := types.GetValue(ident.ProviderDisplayName, "")
descriptor := types.GetValue(ident.Descriptor, "")
if displayName != "" && descriptor != "" {
return fmt.Sprintf("%s (%s)", displayName, descriptor)
}
if displayName != "" {
return displayName
}
return descriptor
}
18 changes: 18 additions & 0 deletions internal/cmd/team/show/show.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if hasText .Url}}
{{bold "url:"}} {{hyperlink .Url .Url}}
{{- end}}
{{- if hasText .Id}}
{{bold "id:"}} {{.Id}}
{{- end}}
{{- if hasText .Name}}
{{bold "name:"}} {{s .Name}}
{{- end}}
{{- if hasText .Description}}
{{bold "description:"}} {{s .Description}}
{{- end}}
{{- if hasText .ProjectName}}
{{bold "project:"}} {{s .ProjectName}} {{if .ProjectId}}({{.ProjectId}}){{end}}
{{- end}}
{{- if hasText .Identity}}
{{bold "identity:"}} {{s .Identity}}
{{- end}}
Loading
Loading