Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Taimoor Ahmad committed Jan 20, 2024
1 parent 50d6a2a commit b367d1f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/cmd/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/opslevel/cli/common"
"os"
"slices"
"strings"

"github.com/opslevel/opslevel-go/v2023"
Expand Down Expand Up @@ -59,7 +60,7 @@ opslevel delete alias -t infrastructure-resource my-infra-alias`,
Run: func(cmd *cobra.Command, args []string) {
alias := args[0]
aliasType := cmd.Flags().Lookup("type").Value.String()
if !Contains(opslevel.AllAliasOwnerTypeEnum, aliasType) {
if !slices.Contains(opslevel.AllAliasOwnerTypeEnum, aliasType) {
log.Error().Msgf("invalid alias type '%s'", aliasType)
os.Exit(1)
}
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var createSystemCmd = &cobra.Command{
cat << EOF | opslevel create system -f -
name: "My System"
description: "Hello World System"
owner: "Z2lkOi8vb3BzbGV2ZWwvVGVhbS83NjY"
ownerId: "Z2lkOi8vb3BzbGV2ZWwvVGVhbS83NjY"
parent:
alias: "alias of domain"
note: "Additional system details"
Expand Down Expand Up @@ -97,7 +97,6 @@ var listSystemCmd = &cobra.Command{
},
}

// TODO: bug in API prevents use of alias in this function. Adding full functionality for now.
var updateSystemCmd = &cobra.Command{
Use: "system ID|ALIAS",
Aliases: common.GetAliases("System"),
Expand All @@ -107,7 +106,7 @@ var updateSystemCmd = &cobra.Command{
cat << EOF | opslevel update system my-system-alias-or-id -f -
name: "My Updated System"
description: "Hello Updated System"
owner: "Z2lkOi8vb3BzbGV2ZWwvVGVhbS83NjY"
ownerId: "Z2lkOi8vb3BzbGV2ZWwvVGVhbS83NjY"
parent:
alias: "my_domain"
note: "Additional system details for my updated system"
Expand Down
15 changes: 3 additions & 12 deletions src/cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"slices"
"sort"
"strings"

Expand Down Expand Up @@ -40,7 +41,7 @@ opslevel create user "[email protected]" "Jane Doe" Admin --skip-welcome-email
role := opslevel.UserRoleUser
if len(args) > 2 {
desiredRole := strings.ToLower(args[2])
if Contains(opslevel.AllUserRole, desiredRole) {
if slices.Contains(opslevel.AllUserRole, desiredRole) {
role = opslevel.UserRole(desiredRole)
}
}
Expand Down Expand Up @@ -144,16 +145,6 @@ var deleteUserCmd = &cobra.Command{
},
}

// TODO: move this to opslevel_common
func Contains[T comparable](s []T, e T) bool {
for _, v := range s {
if v == e {
return true
}
}
return false
}

var importUsersCmd = &cobra.Command{
Use: "user",
Aliases: common.GetAliases("User"),
Expand All @@ -180,7 +171,7 @@ EOF
continue
}
userRole := opslevel.UserRoleUser
if Contains(opslevel.AllUserRole, role) {
if slices.Contains(opslevel.AllUserRole, role) {
userRole = opslevel.UserRole(role)
}
input := opslevel.UserInput{
Expand Down

0 comments on commit b367d1f

Please sign in to comment.