Skip to content

Commit

Permalink
Revert ""opslevel import group" command has been removed"
Browse files Browse the repository at this point in the history
This reverts commit 737f82e.
  • Loading branch information
davidbloss committed Nov 1, 2023
1 parent 737f82e commit 8d8e2d9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .changes/unreleased/Removed-20231101-104007.yaml

This file was deleted.

42 changes: 42 additions & 0 deletions src/cmd/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -280,4 +321,5 @@ func init() {
listCmd.AddCommand(listGroupCmd)
updateCmd.AddCommand(updateGroupCmd)
deleteCmd.AddCommand(deleteGroupCmd)
importCmd.AddCommand(importGroupsCmd)
}

0 comments on commit 8d8e2d9

Please sign in to comment.