From 854c79196d3b504c89a5e8fcba231d3c356f7f33 Mon Sep 17 00:00:00 2001 From: Steve Layton Date: Fri, 5 Feb 2021 14:37:49 -0800 Subject: [PATCH] adding ml command --- cmds/ml.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 cmds/ml.go diff --git a/cmds/ml.go b/cmds/ml.go new file mode 100644 index 0000000..fee7498 --- /dev/null +++ b/cmds/ml.go @@ -0,0 +1,49 @@ +package cmds + +import ( + "fmt" + + lytics "github.com/lytics/go-lytics" + "github.com/urfave/cli" +) + +func init() { + addCommand(cli.Command{ + Name: "ml", + Usage: "Machine Learning Info", + Category: "ML API", + Subcommands: []*cli.Command{ + { + Name: "get", + Usage: "Show details of requested segment", + Action: mlGet, + }, + { + Name: "list", + Usage: "List Machine Learning Models", + Action: mlList, + }, + }, + }) +} +func mlGet(c *cli.Context) error { + if c.NArg() == 0 { + return fmt.Errorf("expected one arg (id)") + } + id := c.Args().First() + item, err := client.GetMLModel(id) + exitIfErr(err, "could not get segment %q from API", id) + resultWrite(c, &item, fmt.Sprintf("segment_%s", item.Name)) + return nil +} + +func mlList(c *cli.Context) error { + items, err := client.GetMLModels() + exitIfErr(err, "could not get segment list") + list := make([]lytics.TableWriter, len(items)) + for i, item := range items { + list[i] = item + } + resultWrite(c, list, "segment_list") + return nil +}