forked from micromdm/micromdm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_devices.go
More file actions
46 lines (37 loc) · 1.09 KB
/
Copy pathremove_devices.go
File metadata and controls
46 lines (37 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"context"
"flag"
"fmt"
"strings"
"github.com/pkg/errors"
"github.com/micromdm/micromdm/platform/device"
)
func (cmd *removeCommand) removeDevices(args []string) error {
flagset := flag.NewFlagSet("remove-devices", flag.ExitOnError)
var (
flIdentifier = flagset.String("udid", "", "device UDID, optionally comma separated")
flSerial = flagset.String("serial", "", "device serial, optionally comma separated")
)
flagset.Usage = usageFor(flagset, "mdmctl remove devices [flags]")
if err := flagset.Parse(args); err != nil {
return err
}
if *flIdentifier == "" && *flSerial == "" {
return errors.New("bad input: device UDID or Serial must be provided")
}
opts := device.RemoveDevicesOptions{}
if *flIdentifier != "" {
opts.UDIDs = strings.Split(*flIdentifier, ",")
}
if *flSerial != "" {
opts.Serials = strings.Split(*flSerial, ",")
}
ctx := context.Background()
err := cmd.devicesvc.RemoveDevices(ctx, opts)
if err != nil {
return err
}
fmt.Printf("removed devices(s): %s\n", strings.Join(append(opts.UDIDs, opts.Serials...), ", "))
return nil
}