/
remove_devices.go
47 lines (38 loc) · 1.11 KB
/
remove_devices.go
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
47
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")
flSerials = flagset.String("serials", "", "device serial, optionally comma-separated")
)
flagset.Usage = usageFor(flagset, "mdmctl remove devices [flags]")
if err := flagset.Parse(args); err != nil {
return err
}
if *flIdentifier == "" && *flSerials == "" {
flagset.Usage()
return errors.New("bad input: device UDID or Serial must be provided")
}
opts := device.RemoveDevicesOptions{}
if *flIdentifier != "" {
opts.UDIDs = strings.Split(*flIdentifier, ",")
}
if *flSerials != "" {
opts.Serials = strings.Split(*flSerials, ",")
}
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
}