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
18 changes: 18 additions & 0 deletions docs/azdo_help_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,24 @@ Aliases
s
```

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

Update a team's name and/or description.

```
--description string New description of the 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.
--name string New name of the team
-t, --template string Format JSON output using a Go template; see "azdo help formatting"
```

Aliases

```
u
```



### 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 @@ -7,6 +7,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)
* [azdo team update](./azdo_team_update.md)

### ALIASES

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

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

Update a team's name and/or description. At least one of --name or
--description must be provided. The team is identified by its name or
GUID inside the project.


### Options


* `--description` `string`

New description of the 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.

* `--name` `string`

New name of the team

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

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


### ALIASES

- `u`

### JSON Fields

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

### Examples

```bash
# Rename a team
azdo team update Fabrikam/"Old Name" --name "New Name"

# Update a team's description only
azdo team update MyOrg/Fabrikam/MyTeam --description "New description"
```

### See also

* [azdo team](./azdo_team.md)
2 changes: 2 additions & 0 deletions internal/cmd/team/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/tmeckel/azdo-cli/internal/cmd/team/create"
"github.com/tmeckel/azdo-cli/internal/cmd/team/list"
"github.com/tmeckel/azdo-cli/internal/cmd/team/show"
"github.com/tmeckel/azdo-cli/internal/cmd/team/update"
"github.com/tmeckel/azdo-cli/internal/cmd/util"
)

Expand All @@ -21,6 +22,7 @@ func NewCmd(ctx util.CmdContext) *cobra.Command {
cmd.AddCommand(create.NewCmd(ctx))
cmd.AddCommand(list.NewCmd(ctx))
cmd.AddCommand(show.NewCmd(ctx))
cmd.AddCommand(update.NewCmd(ctx))

return cmd
}
124 changes: 124 additions & 0 deletions internal/cmd/team/update/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package update

import (
"fmt"

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

type updateOptions struct {
targetArg string
name string
description string
exporter util.Exporter
}

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

cmd := &cobra.Command{
Use: "update [ORGANIZATION/]PROJECT/TEAM",
Short: "Update a team's name and/or description.",
Long: heredoc.Doc(`
Update a team's name and/or description. At least one of --name or
--description must be provided. The team is identified by its name or
GUID inside the project.
`),
Example: heredoc.Doc(`
# Rename a team
azdo team update Fabrikam/"Old Name" --name "New Name"

# Update a team's description only
azdo team update MyOrg/Fabrikam/MyTeam --description "New description"
`),
Aliases: []string{
"u",
},
Args: util.ExactArgs(1, "team argument required"),
PreRunE: func(cmd *cobra.Command, args []string) error {
nameChanged := cmd.Flags().Changed("name")
descChanged := cmd.Flags().Changed("description")
if !nameChanged && !descChanged {
return util.FlagErrorf("at least one of --name or --description is required")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
opts.targetArg = args[0]
return runUpdate(ctx, opts)
},
}

cmd.Flags().StringVar(&opts.name, "name", "", "New name of the team")
cmd.Flags().StringVar(&opts.description, "description", "", "New description of the team")

util.AddJSONFlags(cmd, &opts.exporter, []string{
"id", "name", "description", "url",
"identity", "identityUrl", "projectId", "projectName",
})

return cmd
}

func runUpdate(ctx util.CmdContext, opts *updateOptions) 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)
}

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

payload := &core.WebApiTeam{
Name: types.ToPtr(opts.name),
Description: types.ToPtr(opts.description),
}

updated, err := client.UpdateTeam(ctx.Context(), core.UpdateTeamArgs{
TeamData: payload,
ProjectId: &scope.Project,
TeamId: &scope.Targets[0],
})
if err != nil {
return fmt.Errorf("failed to update team: %w", err)
}

ios.StopProgressIndicator()

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

return renderTeam(ctx, updated)
}

func renderTeam(ctx util.CmdContext, team *core.WebApiTeam) error {
tp, err := ctx.Printer("list")
if err != nil {
return err
}
tp.AddColumns("ID", "NAME", "DESCRIPTION", "PROJECT", "URL")
tp.EndRow()
tp.AddField(types.GetValue(team.Id, uuid.UUID{}).String())
tp.AddField(types.GetValue(team.Name, ""))
tp.AddField(types.GetValue(team.Description, ""))
tp.AddField(types.GetValue(team.ProjectName, ""))
tp.AddField(types.GetValue(team.Url, ""))
tp.EndRow()
return tp.Render()
}
Loading
Loading