Files
micromdm/cmd/mdmctl/remove_devices.go
Scott Knight 529860bf15 Allow removal of device records (#444)
The new remove devices command takes a UDID or list of UDIDs
as input and calls the devices delete endpoint. Since serial number
isn't strictly required by the spec it seemed to make more sense
to keep the remove working with only UDIDs. The get devices command
with a serial number filter can always be used to look up a UDID
from a serial number.
2018-06-21 11:43:16 -04:00

36 lines
745 B
Go

package main
import (
"context"
"flag"
"fmt"
"strings"
"github.com/pkg/errors"
)
func (cmd *removeCommand) removeDevices(args []string) error {
flagset := flag.NewFlagSet("remove-devices", flag.ExitOnError)
var (
flIdentifier = flagset.String("udid", "", "device UDID, optionally comma separated")
)
flagset.Usage = usageFor(flagset, "mdmctl remove devices [flags]")
if err := flagset.Parse(args); err != nil {
return err
}
if *flIdentifier == "" {
return errors.New("bad input: device UDID must be provided")
}
ctx := context.Background()
err := cmd.devicesvc.RemoveDevices(ctx, strings.Split(*flIdentifier, ","))
if err != nil {
return err
}
fmt.Printf("removed devices(s): %s\n", *flIdentifier)
return nil
}