diff --git a/.changes/unreleased/Removed-20231101-104007.yaml b/.changes/unreleased/Removed-20231101-104007.yaml deleted file mode 100644 index ebe90e5c..00000000 --- a/.changes/unreleased/Removed-20231101-104007.yaml +++ /dev/null @@ -1,3 +0,0 @@ -kind: Removed -body: '"opslevel import group" command has been removed' -time: 2023-11-01T10:40:07.550406-05:00 diff --git a/src/cmd/group.go b/src/cmd/group.go index cb57d728..5ae12098 100644 --- a/src/cmd/group.go +++ b/src/cmd/group.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/opslevel/opslevel-go/v2023" + "github.com/rs/zerolog/log" "github.com/opslevel/cli/common" "github.com/spf13/cobra" @@ -269,6 +270,46 @@ var deleteGroupCmd = &cobra.Command{ }, } +var importGroupsCmd = &cobra.Command{ + Use: "group", + Aliases: []string{"groups"}, + Short: "Imports groups from a CSV", + Deprecated: `Please convert all Groups into Teams. See https://docs.opslevel.com/docs/groups`, + Long: `Imports a list of groups from a CSV file with the column headers: +Name,Description,Parent + +Example: + +cat << EOF | opslevel import group -f - +Name,Description,Parent +Engineering,All of Engineering, +Product,All of Product,engineering +Sales,Sales BU,product +EOF +`, + Run: func(cmd *cobra.Command, args []string) { + reader, err := readImportFilepathAsCSV() + cobra.CheckErr(err) + for reader.Rows() { + name := reader.Text("Name") + input := opslevel.GroupInput{ + Name: name, + Description: reader.Text("Description"), + } + parent := reader.Text("Parent") + if parent != "" { + input.Parent = opslevel.NewIdentifier(parent) + } + group, err := getClientGQL().CreateGroup(input) + if err != nil { + log.Error().Err(err).Msgf("error creating group '%s'", name) + continue + } + log.Info().Msgf("created group '%s' with id '%s'", group.Name, group.Id) + } + }, +} + func init() { createCmd.AddCommand(createGroupCmd) getCmd.AddCommand(getGroupCommand) @@ -280,4 +321,5 @@ func init() { listCmd.AddCommand(listGroupCmd) updateCmd.AddCommand(updateGroupCmd) deleteCmd.AddCommand(deleteGroupCmd) + importCmd.AddCommand(importGroupsCmd) }