@@ -28,7 +28,6 @@ func (r *RootCmd) shareWorkspace(orgContext *OrganizationContext) *serpent.Comma
28
28
var (
29
29
client = new (codersdk.Client )
30
30
userAndGroupRegex = regexp .MustCompile (`([A-Za-z0-9]+)(?::([A-Za-z0-9]+))?` )
31
- workspaceRegex = regexp .MustCompile (`([A-Za-z0-9\-]+)(?:\/([A-Za-z0-9\-]+))?` )
32
31
users []string
33
32
groups []string
34
33
)
@@ -55,32 +54,9 @@ func (r *RootCmd) shareWorkspace(orgContext *OrganizationContext) *serpent.Comma
55
54
serpent .RequireRangeArgs (1 , - 1 ),
56
55
),
57
56
Handler : func (inv * serpent.Invocation ) error {
58
- workspaceAndOwner := workspaceRegex .FindStringSubmatch (inv .Args [0 ])
59
-
60
- // Assume the workspace is being given in the format <owner>/<workspace>
61
- // If the owner is an empty string assume just a workspace name was given
62
- ownerUsername := workspaceAndOwner [1 ]
63
- workspaceName := workspaceAndOwner [2 ]
64
- if workspaceName == "" {
65
- workspaceName = workspaceAndOwner [1 ]
66
- ownerUsername = ""
67
- }
68
-
69
- ownerId := codersdk .Me
70
- if ownerUsername != "" {
71
- owner , err := client .User (inv .Context (), ownerUsername )
72
- if err != nil {
73
- return xerrors .Errorf ("could not fetch the workspace owner with the username %s." , ownerUsername )
74
- }
75
-
76
- ownerId = owner .ID .String ()
77
- }
78
-
79
- workspace , err := client .WorkspaceByOwnerAndName (inv .Context (), ownerId , workspaceName , codersdk.WorkspaceOptions {
80
- IncludeDeleted : false ,
81
- })
57
+ workspace , err := namedWorkspace (inv .Context (), client , inv .Args [0 ])
82
58
if err != nil {
83
- return xerrors .Errorf ("could not fetch the workspace %s." , workspaceName )
59
+ return xerrors .Errorf ("could not fetch the workspace %s." , inv . Args [ 0 ] )
84
60
}
85
61
86
62
userRoles := make (map [string ]codersdk.WorkspaceRole , len (users ))
0 commit comments